Skip to content

v4: absorb main 3.5.0, part 5 - pub/sub: retry a failed subscribe from the heartbeat - #3409

Merged
mgravell merged 1 commit into
v4from
marc/v4-absorb-3.5-b4
Dec 3, 2026
Merged

mgravell merged 1 commit into
v4from
marc/v4-absorb-3.5-b4

Conversation

@mgravell

@mgravell mgravell commented Dec 3, 2026

Copy link
Copy Markdown
Member

Fifth slice of absorbing main's 3.5.0 into v4 (after #3403, #3406, #3407, #3408): main's #3387. This completes the pub/sub batch.

The bug (#3371)

A subscribe that fails (declined with BUSY, timed out, or never written) keeps its handler registered, so the subscription is restored when the subscription connection is replaced. Until then nothing retried it, so with the connection up the caller stayed deaf indefinitely. v4 had the same gap.

How it maps onto v4

Every v4 subscribe goes through Subscription.SendAsync, so this is smaller than main's change.

  • Never fire-and-forget on the wire. A fire-and-forget subscribe completed when written, so a declined one went unseen. That includes the restore after a reconnect, which EnsureSubscriptions sends fire-and-forget. It is now sent as a normal command and observed, as v4: absorb main 3.5.0, part 4 - pub/sub: retire subscriptions the server still holds #3408 already does for unsubscribes. A caller who asked for fire-and-forget still doesn't wait.
  • Retry only what can pass. A timeout, a connection failure, or a refusal that reflects the server's own state (BUSY, LOADING, TRYAGAIN: FaultContext.NotApplied) records a retry owed. This is main's IsTransientSubscribeFault. NOPERM and the like would fail the same way forever, so they aren't retried.
  • The heartbeat retries. It consumes the owed flag and re-drives each wanted subscription that has no server, on a server whose subscription connection is up. A single-node subscription uses the internal-restore path, so it defers to any attempt in flight. A multi-node one subscribes each eligible node it lacks. A subscription whose server's connection is down asks for another look at the next heartbeat. An exception in the sweep is reported once, until the sweep runs clean.
  • docs/Basics.md: what happens when subscribing fails, why not to retry with the same handler, and what SubscribedEndpoint returns. Taken from main.

A fire-and-forget subscribe now records its server when it is acknowledged rather than when it is sent. So the fire-and-forget case of OverlappingRestoresCannotSubscribeOnTwoServers, which #3407 had to relax, goes back to main's expectation: the deferred restore counts as a pending change.

Tests

  • FailedSubscribeUnitTests (main's, 44 cases) apply as-is. With the observed send and the heartbeat retry stubbed out, 14 of them fail (every retry case, on both protocols).
  • Wider suites: pub/sub, sharded, RESP3, failover, sentinel, maintenance, endpoint pruning, keyspace isolation and SanityChecks pass: net10.0 818 (108 skipped), net481 814 (107 skipped).
  • Full net10.0 suite against my local servers: the same 112 tests fail on this branch and on current v4, all needing newer server commands or the full topology; nothing fails only here. The branch adds 44 passing tests.

…tion stays up (port of main #3387)

A subscribe that fails (declined with BUSY, timed out, or never written) keeps its handler
registered, so the subscription is restored when the subscription connection is replaced. Until
then nothing retried it, so with the connection up the caller stayed deaf indefinitely (#3371).
v4 had the same gap.

- A subscribe is never sent as fire-and-forget on the wire. A caller who asked for that, including
  the restore after a reconnect, still does not wait, but a declined subscribe is now observed
  rather than completing when written.
- A failure that can pass (a timeout, a connection failure, or a refusal reflecting the server's
  own state: FaultContext.NotApplied) records a retry owed (IsTransientSubscribeFault, as main).
- The heartbeat consumes that and re-drives each wanted subscription that has no server, on a
  server whose subscription connection is up; one that is down asks for another look next time.
  An exception in the sweep is reported once until it runs clean.
- docs/Basics.md: what happens when subscribing fails, and what SubscribedEndpoint returns.

A fire-and-forget subscribe now records its server on the acknowledgement rather than on send, so
the overlapping-restore test's fire-and-forget case goes back to main's expectation (the deferred
restore counts as a pending change).

Main's FailedSubscribeUnitTests (44 cases) apply as-is; with the retry stubbed out, 14 fail.
@mgravell
mgravell merged commit 8d128d8 into v4 Dec 3, 2026
3 checks passed
@mgravell
mgravell deleted the marc/v4-absorb-3.5-b4 branch December 3, 2026 18:03
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.

1 participant