Retry all exceptions from Sentinel replicas#1577
Merged
vladvildanov merged 3 commits intopredis:mainfrom Jul 18, 2025
Merged
Conversation
…Throwable interface
…Throwable interface
Contributor
|
@ridgey-dev Oh, thanks for your contribution! LGTM |
vladvildanov
approved these changes
Jul 17, 2025
tillkruss
approved these changes
Jul 17, 2025
wkerschbaumer
pushed a commit
to wkerschbaumer/predis
that referenced
this pull request
Feb 27, 2026
The getMaster(), getSlaves(), and updateSentinels() methods only catch ConnectionException when connecting to Sentinel nodes. StreamInitException (thrown by stream_socket_client() failures) extends PredisException directly, not ConnectionException, so it propagates uncaught — preventing fallback to the next Sentinel node. This causes complete application failure when any single Sentinel is unreachable, even if other Sentinels are healthy. Add StreamInitException to the catch clause using a union type in all three methods. This is more precise than catching PredisException, which would also swallow ServerException (e.g. "ERR No such master with that name") and mask configuration errors. See also predis#1577 which applied a similar fix to retryCommandOnFailure().
3 tasks
vladvildanov
added a commit
that referenced
this pull request
Mar 5, 2026
* Fix sentinel discovery methods not catching StreamInitException The getMaster(), getSlaves(), and updateSentinels() methods only catch ConnectionException when connecting to Sentinel nodes. StreamInitException (thrown by stream_socket_client() failures) extends PredisException directly, not ConnectionException, so it propagates uncaught — preventing fallback to the next Sentinel node. This causes complete application failure when any single Sentinel is unreachable, even if other Sentinels are healthy. Add StreamInitException to the catch clause using a union type in all three methods. This is more precise than catching PredisException, which would also swallow ServerException (e.g. "ERR No such master with that name") and mask configuration errors. See also #1577 which applied a similar fix to retryCommandOnFailure(). * Fix coding standards and add changelog entry - Remove spaces around | in union catch (php-cs-fixer) - Add CHANGELOG.md entry for #1650 * Codestlye fixes --------- Co-authored-by: Wolfgang Kerschbaumer <wolfgang.kerschbaumer@bergfex.at> Co-authored-by: vladvildanov <vladyslav.vildanov@redis.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In
v2.x, failures from stream_socket_client() would result in aCommunicationException, which is caught and retried bySentinelReplication.In
v3.x, such failures now throw aStreamInitException, which is not a subclass ofCommunicationException, and thus bypasses the existing retry logic.Change
Replaces the catch (
CommunicationException $e) block with catch (Throwable $e)Maintains existing retry behavior, but broadens the scope to handle all exceptions thrown during connection attempts, including
StreamInitExceptionand any future unexpected errors.Justification
Brings retry handling in SentinelReplication in line with the logic already adopted in RedisCluster (#788)