Repository navigation
Conversation
A primary demoted in place (REPLICAOF, or a sentinel failover whose +switch-master was missed) drops no connection, so the client kept routing writes to it until the next periodic INFO replication - up to ConfigCheckSeconds (60s by default) of refused writes. A READONLY reply from a server we treat as a primary now re-reads the role of every connected server, at most once a second per multiplexer; the existing reconfigure and sentinel demotion paths then elect the new primary. Fixes #3383. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
This branch has not been deployed
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 #3383.
A primary demoted in place drops no connection. That covers a
REPLICAOFswitch, and a Sentinel failover whose+switch-masterthe client missed. The client only noticed at the next periodicINFO replication, so for up toConfigCheckSeconds(60s by default) every write went to the old primary and was refused withREADONLY. This happens without Sentinel too: a plain primary/replica configuration gets stuck the same way.Change
When a
READONLYreply comes from a server we treat as a primary, the client re-reads the role (INFO replication) of every connected server, at most once a second per multiplexer. The existing paths then elect the new primary: the reconfigure that a role change triggers, and for a Sentinel-managed connection, the demotion check on the Sentinel heartbeat.IServer.Execute), or in cluster mode, where replicas answerMOVEDrather thanREADONLY.READONLYas before. Re-issuing it to the new primary would be safe, because the server didn't run it, but that changes retry behaviour, so I've left it out.Tests
ReadOnlyReplyUnitTests, against the in-process server, with a subclass that refuses writes on a replica as a real server does:ReadOnlyFromThePrimaryIsNoticedPromptly, via Sentinel and with plain endpoints,ConfigCheckSeconds = 60: swap the roles with no dropped connection and no announcement, then keep writing. On main, writes are still refused 10s later (about 635 refusals). With this change, one write is refused and the next goes to the new primary.RepeatedReadOnlyIsRateLimited: a server that refuses every write but still reports itself a primary. About 235,000 refusals in 2.7s cause 3 role re-reads.ReadOnlyFromAKnownReplicaChangesNothing: a module-style write to a known replica causes no re-reads. This fails if the replica check is removed.The library builds clean across all target frameworks. All
*UnitTestspass on net10.0, with one unrelated flaky test,EndpointPruningUnitTests.NodeCarryingSubscriptionsIsNotPruned, which passed 5 of 5 runs alone. The new tests also pass on net481.