Repository navigation
v4: absorb main 3.5.0, part 3 - pub/sub: overlapping restores cannot register on two servers - #3407
Merged
Merged
Conversation
…vers (port of main #3353, #3376) v4 already keeps overlapping restores apart while one is in flight (HasSendInFlight, standing in for main's claim), but recorded every acknowledgement unconditionally. A restore acknowledged by a second server after the in-flight window (it is bounded by time) replaced the recorded server while the first registration stayed live, delivering every message twice (#3336). - TryAdoptEndpoint: a single-node subscription refuses an ack from a different server while its recorded one is live; the settle path then unsubscribes the stray (fire-and-forget, pinned to that server). Multi-node subscriptions adopt every ack. - Only an internal restore defers to the attempt in flight, and counts as a pending change (1, not 0); a user subscribe sends its own and returns once that is acknowledged, as main's review follow-up. - Clearing a stale recorded server is a compare-and-swap (EnsureSubscribedToServer[Async], RemoveIncorrectRouting, RemoveDisconnectedEndpoints), so a live server recorded by a concurrent ack is not wiped. Main's SubscriptionRestoreRaceTests come across with the old-core sends replaced by v4's; all 16 failed on v4 before this. The fire-and-forget overlap case expects 0 rather than 1 from the deferred restore, because v4 records a fire-and-forget subscribe's server when it is sent. Main's MultiNodeSubscriptionTrackingTests (#3376's rename) applies as-is.
This was referenced Dec 3, 2026
mgravell
added a commit
that referenced
this pull request
Dec 3, 2026
… restore and the heartbeat (port of main #3368) (#3408) Unsubscribing a channel's last handler retires its subscription on the client whether or not the server-side unsubscribe succeeds. v4 had main's gap: a declined (BUSY, LOADING, MASTERDOWN) or timed-out UNSUBSCRIBE, or one sent while the SUBSCRIBE was still unacknowledged, left the server subscribed with nothing left to clean it up until the connection was replaced. - Subscription: a retiring state readable without the registration lock, plus a retry-needed flag consumed before re-issuing, so a slow reply is not re-sent on every heartbeat. Restore paths skip retired subscriptions. - The UNSUBSCRIBE is never sent as fire-and-forget, though a caller who asked for that still does not wait, so a declined one is always observed. An incomplete one records the server and is tracked by the multiplexer, which re-issues it from the heartbeat and from EnsureSubscriptions unless a newer subscription owns, or may yet claim, that server. - An unsubscribe while the subscribe is in flight goes out behind it on the same connection, so the caller does not return with the server still subscribed. An ack for a retired subscription, or a stray for a live one, is unsubscribed as a tracked retirement. - Self-correction: an older UNSUBSCRIBE that lands after a newer subscription for the channel was restored onto the same server re-subscribes that one. - The synchronous Unsubscribe surfaces the server's exception rather than an AggregateException. Also from main's SubscriptionRestorationTests, which #3353 created and #3407 missed: - a timed-out subscribe's server is tracked as a possible stray, since its late ack reaches nobody in v4; - an internal restore that deferred to an in-flight attempt is re-driven when that attempt fails; - UnsubscribeAsync's task carries the subscriber's async state (an existing v4 bug). Main's FailedUnsubscribeUnitTests (14 of 18 failed on v4) and SubscriptionRestorationTests come across with old-core sends replaced by v4's; the bridge-identity test keeps its intent (restored on the new connection, and delivers) without the PhysicalBridge assertions.
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.
Third slice of absorbing main's 3.5.0 into v4 (after #3403 and #3406): main's fix for overlapping subscription restores registering on two servers. #3368 and #3387 follow separately.
Covered
HasSendInFlight. Reconcile at the ack: v4 lacked this. It recorded every acknowledgement unconditionally, so a restore acknowledged by a second server after the in-flight window (which is bounded by time) replaced the recorded server while the first registration stayed live, delivering every message twice (#3336).TryAdoptEndpointapplies as-is.Changes (
Subscription.cs)TryAdoptEndpoint: a single-node subscription refuses an ack from a different server while its recorded one is live. The settle path then unsubscribes the stray, fire-and-forget and pinned to that server. Multi-node subscriptions adopt every ack.OnSubscribedkeeps the unconditionalAddEndpoint.EnsureSubscribedToServer[Async],RemoveIncorrectRoutingandRemoveDisconnectedEndpoints.Tests
Main's
SubscriptionRestoreRaceTestscome across with the old-core sends replaced by v4's: a ping on the second server's subscription socket as the barrier, andSubscription.SendAsyncfor the stray. All 16 failed on v4 before the change; they pass now.One expectation differs from main. In the fire-and-forget overlap case the deferred restore returns 0, not 1, because v4 records a fire-and-forget subscribe's server when it is sent, not when it is acknowledged (so that a flush finds the right socket). The second restore therefore reads it as already subscribed. The assertions that matter (no
SUBSCRIBEreaches the second server, and the first server is the one recorded) are unchanged.The pub/sub, failover, endpoint-pruning, retirement and SanityChecks suites pass on net10.0 (and, before the rebase onto #3406, on net481).