Repository navigation
Pub/sub: a publish that demands a primary does not follow a subscription onto a replica (#3357) - #3380
Merged
Conversation
…ion onto a replica (#3357) A publish to a subscribed channel is sent to the server the channel is subscribed on. A subscription stays where it was made, even after a role change, so after a promotion that server can be a replica; a publish with DemandMaster was then refused locally ("Command cannot be issued to a replica: PUBLISH"), indefinitely, even with the new primary known and every other command routing to it. The subscribed server is now only used when it satisfies the publish's primary/replica demand (DemandMaster: not a replica; DemandReplica: a replica); otherwise normal server selection applies. Without a demand, behavior is unchanged.
…e role change ConfigureAsync is a no-op while another reconfigure is in flight, so a single call could leave the client never re-reading roles (seen on CI, both OSes). Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
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 #3357.
A publish to a subscribed channel goes to the server the channel is subscribed on (
GetSubscribedServer), whatever the flags. A standalone subscription stays where it was made, even after a role change; it keeps working on a replica, so nothing moves it. After a promotion, aPublishAsync(..., CommandFlags.DemandMaster)to that channel is sent to the old primary, now a replica, and is refused locally withCommand cannot be issued to a replica: PUBLISH. That continues indefinitely, even though the client knows the new primary and every other command routes to it.Change
A new internal
GetPublishServer(channel, flags)uses the subscribed server only if it satisfies the publish's primary/replica demand:DemandMaster, it must not be a replica;DemandReplica, it must be a replica.Otherwise it returns
null, and normal server selection applies. All four publish paths (ISubscriberandIDatabase, sync and async) use it. A publish without a demand is unchanged: it still uses the subscribed server.No public API change. The subscription itself is not moved; that's a separate question.
Tests
PublishRoutingUnitTests, against the in-process server with a primary and a replica, run for both protocols:DemandMasterPublishFollowsTheNewPrimary: subscribe, swap roles with no disconnect, then aDemandMasterpublish reaches the new primary. CoversISubscriberandIDatabase, sync and async.DemandReplicaPublishDoesNotUseAPrimarySubscription.UndemandingPublishStillUsesTheSubscribedServer: pins the unchanged default.Without the fix, the first two fail with the error from the issue; the third passes either way, as intended. The library builds clean in Release across all TFMs with analyzers, and all 1232
*UnitTestspass on net10.0.