Repository navigation
Pub/Sub: retry a last unsubscribe the server declined, rather than leaving it subscribed - #3368
aradalvand wants to merge 1 commit into
Conversation
903d730 to
ebe2190
Compare
|
Thanks - the diagnosis in #3367 is accepted, and the I don't want to merge the retry loop as it stands: it gives up after 30 attempts, so the leak is bounded but not closed; each failure starts its own background task with no tie to multiplexer shutdown; and there is the timed-out-then-declined hole you already called out. I'd prefer the client to remember "retire pending" as state and let the existing heartbeat and restore path drive it, which also covers a related gap (unsubscribe while a subscribe is unacknowledged). That work is tracked in #3375, and I'd like to use your I'll leave this open until that lands, in case it is useful as a reference. #3363, which this builds on, has a separate review. Unrelated to your change: the earlier Ubuntu failure here was a flake in the in-process test server. |
…ore, and heartbeat Replaces the per-failure background retry loop with an explicit retiring state on Subscription driven by the existing ack, restore, and heartbeat paths (addressing seredis#3367 and items 1-2 of seredis#3375): - Make Subscription.IsRetired safely readable without RegistrationLock (Interlocked.Exchange / Volatile.Read) and skip retired subscriptions in EnsureSubscriptions, EnsureSubscribedToServer[Async], Release, ResubscribeToServer, and ResubscribeStrandedShardedChannels. - Track retiring subscriptions that still have server endpoints in ConnectionMultiplexer._retiringSubscriptions and drive them from OnHeartbeat() and EnsureSubscriptions(), cleaning up disconnected endpoints in UpdateSubscriptions(). - Honour IsRetired in TryAdoptEndpoint and TrackSubscriptionsProcessor.SetResultCore so late SUBSCRIBE acks on retired subscriptions (e.g. unsubscribed while a subscribe was in flight) are cleaned up without disturbing a newer active subscription on the same or another server. - Queue async unsubscribes behind an in-flight SingleNodeSubscription subscribe on the pending server so async callers wait for the unsubscribe. - Keep FailedUnsubscribeUnitTests (plus timed-out-then-declined and restore-skips-retired cases) and add the four in-flight subscribe/unsubscribe acceptance tests from seredis#3337/seredis#3375 in SubscriptionRestorationTests.
ebe2190 to
e22fafa
Compare
|
Thanks for the feedback — I've rebased onto
|
Fixes #3367.
Unsubscribing a channel's last handler retires its subscription on the client whether or not the server-side unsubscribe succeeds. When the server declined to run it, for example with a
BUSYreply while a script runs, it stays subscribed. It keeps pushing messages that nothing receives, and nothing is left on the client to unsubscribe, until the connection is replaced. This happens for awaited, synchronous andFireAndForgetunsubscribes alike.Changes
ConnectionMultiplexer.OnUnsubscribeNotAppliedre-issues the retired subscription's unsubscribe, with backoff from 100ms up to 5s, at most 30 attempts, unless the channel has been subscribed to again by then, at which point client and server agree once more. It's called once per failure, including failures of the re-issued unsubscribes, from wherever that failure is observed:TrackSubscriptionsProcessor.SetResult(now overridden) handles error replies. It checks whether an error reply to anUNSUBSCRIBE/SUNSUBSCRIBE/PUNSUBSCRIBEof a retired subscription is one where the server never ran the command (FaultContext.IsKnownNotApplied:BUSY,LOADING,MASTERDOWN, …). Reply processing sees every reply, so this works whether or not anyone awaits the command;FireAndForgetincluded.ObserveUnsubscribe(on the returned task) and the sync path'scatchhandle failures with no reply at all, where the command was never written (FaultContext.NotApplied). Server errors are left to the processor, so nothing is retried twice.Things worth a reviewer's eye
TryIssueWhileUnsubscribed. It holds the same lock asGetOrAddSubscription, and only issues the command if the channel still has no subscription. A subscription added afterwards therefore has its subscribe command issued after the unsubscribe. Like Pub/Sub: don't orphan a subscribe that races the last unsubscribe of the same channel #3363, this relies on commands to the same bridge being written in the order they're issued.IsRetiredin the processor withoutRegistrationLock. A subscription is retired before its unsubscribe command is issued, so before that command's reply can be read. The flag also never goes back fromtrue.Subscription's own server(s), where the server-side subscription actually lives. An error reply doesn't clear_currentServer.OnBridgeHeartbeat), butMessage.ComputeResultskips processing the late reply of a command whose result box has already faulted. So:FireAndForgetunsubscribe's late error reply is handled (it has no box);ObserveUnsubscribe(NotApplied, by its status);Testing
FailedUnsubscribeUnitTests, run for both protocols, against an in-process server that repliesBUSYtoUNSUBSCRIBEa given number of times:DeclinedLastUnsubscribeIsRetried(async),DeclinedSyncLastUnsubscribeIsRetriedandDeclinedFireAndForgetLastUnsubscribeIsRetried: the server ends up unsubscribed (PUBLISHreaches 0 clients). Without the fix, all three fail on both protocols.RetriedUnsubscribeDoesNotUndoNewerSubscription: subscribing again right after the failure isn't undone by the retries.*UnitTestsclasses pass (1229, onnet10.0).FireAndForget:Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01XUNs4qcAQaGCRpkwmr8LnY