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 4 commits 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
Copy link

stale bot commented Jul 26, 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 Jul 26, 2024
@martinslota
Copy link
Author

I’m still hopeful that this bug fix will eventually get some attention from a maintainer.

In the meantime, I will make sure to deploy the fix as part of our code to gain additional confidence. I will report again when it has been out for a while.

@stale stale bot removed the wontfix label Jul 29, 2024
@manast
Copy link
Member

manast commented Aug 16, 2024

@martinslota have you checked how connections are handled in BullMQ? I have spent quite a lot of time trying to iron out all connection issues, including workarounds for ioredis bugs when blocking commands gets disconnected: https://github.com/taskforcesh/bullmq/blob/master/src/classes/redis-connection.ts

@martinslota
Copy link
Author

@manast No, I haven't - thank you for the reference! 🙇

We have just adopted this small fix in our code and it will be going to production today.

Would it be possible to backport the connection fixes to Bull? Or would your recommendation be to migrate to BullMQ? We have not explored what it would take to do but I think having fewer random connection errors could make it worth the effort.

@manast
Copy link
Member

manast commented Aug 19, 2024

Would it be possible to backport the connection fixes to Bull? Or would your recommendation be to migrate to BullMQ? We have not explored what it would take to do but I think having fewer random connection errors could make it worth the effort.

Actually no as the way connections are handled in Bull is quite different so it is not trivial to do.

Copy link

stale bot commented Oct 19, 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 Oct 19, 2024
@martinslota
Copy link
Author

We have had this fix in production for around 2 months now and it has really helped reduce the amount of non-actionable Redis connection errors during shutdown (when we pause Bull queues).

Perhaps it could make sense to get the fix merged.

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

Successfully merging this pull request may close these issues.

2 participants