-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: develop
Are you sure you want to change the base?
fix: avoid race condition when reconnecting #2716
Conversation
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. |
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. |
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. |
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. |
@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 |
@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. |
Actually no as the way connections are handled in Bull is quite different so it is not trivial to do. |
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. |
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. |
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 inioredis
. 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 howbull
re-establishes the blocking connection whenpause()
is called. Specifically, the promise returned byredisClientDisconnect
may get resolved before this disconnect() call is executed, causingioredis
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'squit()
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()
withinredisClientDisconnect
if the promise is already resolved at that point.