Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal method can be overwritten #844

Open
yukha-dw opened this issue Jan 5, 2024 · 4 comments
Open

Internal method can be overwritten #844

yukha-dw opened this issue Jan 5, 2024 · 4 comments

Comments

@yukha-dw
Copy link

yukha-dw commented Jan 5, 2024

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 yukha-dw changed the title Internal method can be overwrite Internal method can be overwritten Jan 5, 2024
Copy link
Contributor

github-actions bot commented Feb 5, 2024

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

@lholmquist
Copy link
Member

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

@yukha-dw
Copy link
Author

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

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants