-
Notifications
You must be signed in to change notification settings - Fork 111
Open
Description
Node.js Version:
v18.16.1
Operating System:
Windows 10
Steps to Produce Error:
When we create CircuitBreaker on method called 'fire' (other internal method name could be overwritten too), Circuit Breaker will be broken, for example:
cb = new CircuitBreaker(anotherCB.fire, options);
Result:
ERROR [2024-01-05 08:03:57] (22864): Cannot read properties of undefined (reading 'call')
err: {
"type": "TypeError",
"message": "Cannot read properties of undefined (reading 'call')",
"stack":
TypeError: Cannot read properties of undefined (reading 'call')
at fire (C:\repo\node_modules\opossum\lib\circuit.js:561:17)
at Function.fire (C:\repo\node_modules\opossum\lib\circuit.js:561:17)
at C:\repo\node_modules\opossum\lib\circuit.js:678:38
at new Promise (<anonymous>)
at CircuitBreaker.call (C:\repo\node_modules\opossum\lib\circuit.js:651:12)
at CircuitBreaker.fire (C:\repo\node_modules\opossum\lib\circuit.js:561:17)
at Object.get (file:///C:/repo/get.ts:40:50)
at preHandlerCallback (C:\repo\node_modules\fastify\lib\handleRequest.js:128:37)
at preValidationCallback (C:\repo\node_modules\fastify\lib\handleRequest.js:112:5)
at handler (C:\repo\node_modules\fastify\lib\handleRequest.js:76:7)
}
Simple Fix
cb = new CircuitBreaker(async (params: P): Promise<R[]> => {
return anotherCB.fire(params);
}, options);