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: Only attempt to disconnect idle client instances #6

Closed
wants to merge 1 commit into from

Commits on Oct 28, 2020

  1. FIX: Only attempt to disconnect idle client instances

    Waiting to acquire the mutex on the `::Redis` objects is likely to cause a deadlock in multi-threaded environments. For example:
    
    - Thread 1 and thread 2 have in-progress redis requests during a failover
    - Thread 1 is the first to raise an exception, triggers RailsFailover::Redis::Handler#disconnect_clients, acquiring the RailsFailover::Redis::Handler mutex
    - Thread 1 loops through all ::Redis instances, acquire their locks, and disconnect them
    - When it reaches the ::Redis instance used by Thread 2, Thread 1 waits for the mutex to become available
    
    - Meanwhile, Thread 2 raises an exception and triggers RailsFailover::Redis::Handler#disconnect_clients
    - Thread 2 waits for the RailsFailover::Redis::Handler mutex to become available
    
    This situation is never resolved, and the threads remained deadlocked.
    
    This commit will skip disconnecting `::Redis` clients which are currently locked by another thread. If the lock is held by another thread, it is fair to assume that a request is in process, it will fail, and the client will automatically disconnect very soon.
    davidtaylorhq committed Oct 28, 2020
    Configuration menu
    Copy the full SHA
    274d41f View commit details
    Browse the repository at this point in the history