这是indexloc提供的服务,不要输入任何密码
Skip to content

Internal method can be overwritten #844

@yukha-dw

Description

@yukha-dw

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions