Skip to content

Sentinel: don't re-read topology after repeated connect failures - #3392

Merged
mgravell merged 1 commit into
mainfrom
marc/sentinel-connect-failure-refresh
Dec 2, 2026
Merged

mgravell merged 1 commit into
mainfrom
marc/sentinel-connect-failure-refresh

Conversation

@mgravell

@mgravell mgravell commented Dec 2, 2026

Copy link
Copy Markdown
Member

Fixes #3391.

Under sentinel, ServerEndPoint.OnRepeatedConnectFailure now returns without re-reading the topology. That matches how a sentinel-managed connection already handles READONLY (#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

  • New 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 of SentinelPrimaryDemotionUnitTests running in parallel, it failed in 7 of 8 runs before the fix and 0 of 8 after.
  • All *Sentinel* classes, ConnectFailureRefreshTests and PeriodicTopologyRefreshTests pass on net10.0. The docker-backed sentinel integration tests skipped locally; CI covers them.

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
mgravell merged commit 6217847 into main Dec 2, 2026
4 of 5 checks passed
@mgravell
mgravell deleted the marc/sentinel-connect-failure-refresh branch December 2, 2026 16:35
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".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentinel: a dead replica is never retired while its connect failures keep re-reading topology

1 participant