Repository navigation
Sentinel: don't re-read topology after repeated connect failures - #3392
Merged
Merged
Conversation
Under sentinel, the connect-failure refresh re-read the endpoints we already hold, dialling the dead node while holding the reconfigure gate. Repeated every interval, that starved the replica reconcile (which stands aside while the gate is held), so a dead replica sentinel had dropped was never retired. Sentinel is what follows the topology there, so a sentinel-managed connection now skips the refresh, as it already defers READONLY handling to the sentinel owner.
mgravell
added a commit
that referenced
this pull request
Dec 3, 2026
…role re-read (#3385, #3391, #3384) (#3411) * Sentinel: follow the replicas sentinel lists, not only on a switch to a new primary (#3385) * Sentinel: follow the replicas sentinel lists, not only on a switch to a new primary A managed connection read SENTINEL REPLICAS only at connect and when a switch named a primary at an address it had never seen. A replica that left stayed held, its bridge reconnecting for the life of the connection; one that joined was never used (#3378). The managed connection's replicas are now reconciled every ConfigCheckSeconds from the sentinel connection's heartbeat, and at the next heartbeat after +slave or +reset-master: - a listed replica we do not hold is added once sentinel does not hold it down (s_down/o_down/disconnected), so a replica down during a rolling restart joins on a later run; - a node is retired only when it is not the sentinel-reported primary, is disconnected, and three consecutive periodic replies leave it out or hold it down. A connected node is kept whatever sentinel says; an empty reply, or a run an event started, retires nothing. It stands aside while a switch, reconnect or reconfigure is running, and holds the reconfigure gate while it changes the endpoint set. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ * Move the replica log event beside the server-retirement one Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ * Update #3301's sentinel tests for the replica reconcile Three tests asserted that a dead replica stays held, or that a newly listed one is not added, with no change of primary. That is the behaviour #3378 changes: with ConfigCheckSeconds = 1 the reconcile retires such a replica after about three seconds, so the assertions raced it (and lost on net481 in CI). They now wait for the replica set to follow sentinel, and keep their checks that primary recovery is not kept alive. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ * Sentinel: don't re-read topology after repeated connect failures (#3391) (#3392) Under sentinel, the connect-failure refresh re-read the endpoints we already hold, dialling the dead node while holding the reconfigure gate. Repeated every interval, that starved the replica reconcile (which stands aside while the gate is held), so a dead replica sentinel had dropped was never retired. Sentinel is what follows the topology there, so a sentinel-managed connection now skips the refresh, as it already defers READONLY handling to the sentinel owner. * Re-read server roles promptly when a primary answers READONLY, without sentinel (port of main #3384) A primary demoted in place (REPLICAOF, or a sentinel failover whose +switch-master was missed) drops no connection, so writes kept going to it until the next periodic role check. A READONLY reply from a node still treated as a primary now re-reads the role of every connected node, at most once a second per multiplexer (main's OnReadOnlyReply / TryClaimReadOnlyRoleCheck). On v4 the hook is the READONLY check in RespClientConnection.TryHandOff (added for #3301), which now splits as main's ResultProcessor does: sentinel-managed marks the node as a replica, otherwise OnReadOnlyReply. The re-read is TryRefreshRole (ROLE) rather than INFO replication. Test adjustments: ReadOnlyReplyUnitTests counts ROLE as a role read too; and in the window between the demotion being noticed and the new primary elected, v4 refuses the write client-side (the node is now known to be a replica) where v3 had no connection, so both count as "no writable server yet".
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.
Fixes #3391.
Under sentinel,
ServerEndPoint.OnRepeatedConnectFailurenow returns without re-reading the topology. That matches how a sentinel-managed connection already handlesREADONLY(#3384): the sentinel owner follows the topology, through the replica reconcile and primary recovery. A re-read only asks the endpoints we already hold, so it can't learn that a node has gone. Worse, it dials the dead node while holding the reconfigure gate. Repeated every interval, that starves the replica reconcile, so the dead replica is never retired.Testing
RepeatedConnectFailuresDoNotHoldTheReconfigureGate: after repeated connect failures are reported for a sentinel-managed replica, the reconfigure gate is still free. It fails without the fix ("a connect-failure re-read took the reconfigure gate") and passes with it.KnownHealthyPrimaryKeepsItsEndPointsAndStopsRecovery, the CI flake that exposed this: with eight copies ofSentinelPrimaryDemotionUnitTestsrunning in parallel, it failed in 7 of 8 runs before the fix and 0 of 8 after.*Sentinel*classes,ConnectFailureRefreshTestsandPeriodicTopologyRefreshTestspass on net10.0. The docker-backed sentinel integration tests skipped locally; CI covers them.