Add retries to connections in Sentinel Pools #1879
Merged
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.
Pull Request check-list
Please make sure to review and check all of these items:
$ tox
pass with this change (including linting)?NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
Currently, when using sentinel, if a master dies suddenly (i.e. is
kill -9
'd), and the client is configured with retries, the client will attempt to reconnect to the master using the sentinel pool, as expected.However, if the sentinels have not yet figured out that the master is dead, a
redis.exceptions.ConnectionError
will be returned when trying to re-connect to the old master even ifConnectionError
is in the list of retry errors.This PR fixes this by making sure that the initial connection itself in the SentinelPool is also retryable. This has been tested with a script that increments a counter by 1 every second and then running
kill -9
on the Redis master. As expected, there's a delay while the sentinels figure out what the new master should be, and then the script continues.I'm not very familiar with the code, so I'm not sure if this is the ideal place for this code. It is possible that it would make more sense to put it in the connection itself.
While this will need a new test, I'm not sure how to create an automated test that
kill -9
s one of the Redis servers, I'm not sure if this fix needs documentation, and I'm not sure if I should add an example