Skip to content

Worker can get caught in infinite loop when redis connection is closed unexpectedly #389

Closed
@airhorns

Description

Because of https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L192-L195 , I am seeing workers get caught in an infinite loop of trying to get the next job only to error again trying to get the next job.

The loop is this:

  • Redis connection is closed somehow (I assume this is my code doing this but don't have a smoking gun yet)
  • worker is not closed explicitly, this.closing inside the worker is undefined
  • worker run loop calls getNextJob asynchronously, which calls waitForJob, which calls BRPOPLPUSH
  • Redis client synchronously throws, which interrupts execution of waitForJob, and is caught in getNextJob, and swallowed
  • getNextJob call wins the Promise.race in worker run loop
  • getNextJob call returns nothing, so worker doesn't work the job
  • worker run loop repeats the process

I am not sure why that error is being swallowed, or why the Connection is closed. message is special. If I had to guess, special care has to be taken to handle connection closes that we expect on the blocking calls like that. In this case though, the worker has not been explicitly closed, and it's being asked to use a closed redis connection, which I think should be an error that at least gets emitted and maybe takes down the process if unhandled.

Happy to do up a PR if someone can tell me what the semantics should be!

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions