Fix sentinel discovery methods not catching StreamInitException#1650
Merged
vladvildanov merged 3 commits intopredis:mainfrom Mar 5, 2026
Merged
Conversation
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().
vladvildanov
approved these changes
Feb 27, 2026
- Remove spaces around | in union catch (php-cs-fixer) - Add CHANGELOG.md entry for predis#1650
tillkruss
approved these changes
Feb 27, 2026
Contributor
|
@wkerschbaumer Hey! We're good to go with this PR as soon as you'll fix coding standards issue. Most likely it would be solved by just calling |
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.
Summary
getMaster(),getSlaves(), andupdateSentinels()only catchConnectionExceptionwhen connecting to Sentinel nodes.StreamInitException(thrown bystream_socket_client()failures inStreamFactory) extendsPredisExceptiondirectly — notConnectionException— so it propagates uncaught, preventing fallback to the next Sentinel node.retryCommandOnFailure()loop retrying the same dead Sentinel.StreamInitExceptionto the catch clause via union type in all three methods. This is more precise than catchingPredisExceptionorThrowable, which would also swallowServerException(e.g.ERR No such master with that name) and mask configuration errors.Related: #1577 applied a similar fix to
retryCommandOnFailure()but missed these three sentinel discovery methods.Exception hierarchy context
How to reproduce
stream_socket_client()to the dead Sentinel throwsStreamInitExceptiongetMaster()/getSlaves()/updateSentinels()don't catch it → no fallback to the next SentinelretryCommandOnFailure()catches it, but retries hit the same dead Sentinel every timeTest plan
StreamInitExceptionduring sentinel discovery triggers fallback to next sentinelServerException(e.g. wrong service name) still propagates without retry