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: Force redis disconnect if lock acquisition takes too long #8

Closed
wants to merge 11 commits into from

Conversation

davidtaylorhq
Copy link
Member

Previously we were waiting to acquire the mutex for each connection before disconnecting it. This tries to ensure a clean disconnection, but has two issues:

  • It will block forever on long-running redis commands (e.g. Pub/Sub subscriptions)
  • When two clients trigger failover simultaneously, it can cause a deadlock where they each wait for the other's mutex

This commit adds a 50ms timeout, after which the client is terminated forcefully. This may cause some form of Redis::BaseConnectionError, but we expect to see some errors like this during failover anyway, so consumers should be tolerant to it.

This commit also fixes the disconnection for redis SubscribedClient instances, which were previously being skipped.

Previously we were waiting to acquire the mutex for each connection before disconnecting it. This tries to ensure a clean disconnection, but has two issues:

- It will block forever on long-running redis commands (e.g. Pub/Sub subscriptions)
- When two clients trigger failover simultaneously, it can cause a deadlock where they each wait for the other's mutex

This commit adds a 50ms timeout, after which the client is terminated forcefully. This may cause some form of Redis::BaseConnectionError, but we expect to see some errors like this during failover anyway, so consumers should be tolerant to it.

This commit also fixes the disconnection for redis SubscribedClient instances, which were previously being skipped.
@davidtaylorhq davidtaylorhq marked this pull request as draft October 30, 2020 13:25
@davidtaylorhq
Copy link
Member Author

This still doesn't work... more refinement needed

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

Successfully merging this pull request may close these issues.

None yet

1 participant