opossum icon indicating copy to clipboard operation
opossum copied to clipboard

Internal method can be overwritten

Open yukha-dw opened this issue 2 years ago • 4 comments

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);

yukha-dw avatar Jan 05 '24 08:01 yukha-dw

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Feb 05 '24 00:02 github-actions[bot]

if you would like to submit a PR, that could be helpful

lholmquist avatar Mar 21 '24 17:03 lholmquist

I'd love to, but i don't think i have enough knowledge to make it secure. My apology

yukha-dw avatar Mar 22 '24 02:03 yukha-dw

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Apr 22 '24 00:04 github-actions[bot]