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.

Copy link

stale bot commented May 25, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 25, 2024
@martinslota
Copy link
Author

I'd love to keep this pull request alive because the bug it fixes is affecting our production deployments and it generates quite a bit of noise.

@manast I apologize for cold-tagging you here - I'd appreciate any pointers or suggestions regarding how I could take this pull request further.

@stale stale bot removed the wontfix label May 26, 2024
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