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

fix: avoid race condition when reconnecting #2716

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

martinslota
Copy link

Background

We have been seeing occasional Connection is aborted errors when pausing a Bull queue that is backed by Redis in cluster mode. The investigation led to this fix in ioredis. After deploying that fix, the errors became a lot more rare, but they still pop up from time to time - sometimes days apart.

The debug logs from ioredis led me to believe that the issue may be around how bull re-establishes the blocking connection when pause() is called. Specifically, the promise returned by redisClientDisconnect may get resolved before this disconnect() call is executed, causing ioredis to abort its already ongoing connection attempt.

Attempts to reliably reproduce the bug have led to this repository where ioredis is intentionally modified to slightly delay the resolution of the promise returned from the Redis cluster client's quit() method in order to provoke the bug into occurring. All that is then necessary is to create a queue and repeatedly pause/resume it.

Change

Avoids calling client.disconnect() within redisClientDisconnect if the promise is already resolved at that point.

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

Successfully merging this pull request may close these issues.

None yet

1 participant