Skip to content

Retry all exceptions from Sentinel replicas#1577

Merged
vladvildanov merged 3 commits intopredis:mainfrom
ridgey-dev:sentinel-replication-stream-init-exception
Jul 18, 2025
Merged

Retry all exceptions from Sentinel replicas#1577
vladvildanov merged 3 commits intopredis:mainfrom
ridgey-dev:sentinel-replication-stream-init-exception

Conversation

@ridgey-dev
Copy link
Copy Markdown
Contributor

@ridgey-dev ridgey-dev commented Jul 16, 2025

In v2.x, failures from stream_socket_client() would result in a CommunicationException, which is caught and retried by SentinelReplication.

In v3.x, such failures now throw a StreamInitException, which is not a subclass of CommunicationException, 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 StreamInitException and any future unexpected errors.

Justification
Brings retry handling in SentinelReplication in line with the logic already adopted in RedisCluster (#788)

@ridgey-dev ridgey-dev requested a review from a team as a code owner July 16, 2025 15:03
@ridgey-dev ridgey-dev changed the title Retry SentinelReplication::retryCommandOnFailure on all classes with Throwable interface Retry all exceptions from Sentinel replicas Jul 16, 2025
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 16, 2025

Coverage Status

coverage: 93.089% (+0.03%) from 93.064%
when pulling bb57396 on ridgey-dev:sentinel-replication-stream-init-exception
into c60003a on predis:main.

@vladvildanov
Copy link
Copy Markdown
Contributor

@ridgey-dev Oh, thanks for your contribution! LGTM

@vladvildanov vladvildanov merged commit 8e7afbe into predis:main Jul 18, 2025
29 checks passed
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().
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants