Always refresh Resque's redis connection in spawned workers #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the initial batch of workers is spawned by the resque-pool master process, the master will not generally be in possession of a Redis connection. However, as soon as one of the workers dies and needs to be respawned, the resque-pool master will establish a Redis connection in order to enumerate the resque queues, via the call to
Worker#queues
in reap_all_workers.When this happens, the first worker after the initial batch that's spawned by the resque-pool master will inherit resque's Redis connection from the resque-pool master, and will try to use it.
With older versions of the redis-rb gem (pre 3.1.0), or with the inherit_socket option, this will cause an exception in the newly-spawned worker, and make the resque-pool master get into a loop wherein it tries and fails repeatedly to spawn a new worker.
This change ensures that a new Redis connection is always established inside of newly-spawned resque worker processes, avoiding the bad state. While it would be possible to do this manually via an after_prefork hook manually, the manifestation of this problem is pretty non-obvious, because of the fact that it doesn't happen for the first batch of spawned workers, so it seems considerate to do the right thing out of the box, and avoid the unpleasant surprise when a worker dies.