Skip to content

v4: a sync unsubscribe doesn't wait behind an in-flight subscribe - #3421

Merged
mgravell merged 1 commit into
v4from
marc/v4-subscription-restoration-test
Dec 4, 2026
Merged

mgravell merged 1 commit into
v4from
marc/v4-subscription-restoration-test

Conversation

@mgravell

@mgravell mgravell commented Dec 4, 2026

Copy link
Copy Markdown
Member

A synchronous Unsubscribe that races an in-flight subscribe queues its UNSUBSCRIBE behind that subscribe on the same connection. On v4 it then waited for the reply. That reply can't arrive before the subscribe's, so the caller blocked for the whole sync timeout, and then:

  • returned, if its own wait ran out first; or
  • threw RedisTimeoutException, if the command's timeout won.

Which of the two happened came down to timing, and that race is what flaked SyncUnsubscribeDuringInFlightSubscribeThatTimesOutStillUnsubscribes on Windows CI. main doesn't wait in this case: it queues the unsubscribe and returns, so UnsubscribeAll doesn't stall behind it either.

v4 now does the same. The change is limited to a sync caller and an unsubscribe queued behind an in-flight subscribe. That unsubscribe is still sent as an ordinary command, never fire-and-forget, so a declined or timed-out one is still retried. Async callers still await it, as on main.

The test

The test's comment said the unsubscribe was fire-and-forget, which wasn't true on v4. It now matches the behaviour. I also raised the test's sync timeout to 10s, against a 500ms async timeout. That makes the old behaviour fail every time with the same error CI saw (4/4, twice), not just on a slow runner. With the fix it passed 10 runs out of 10.

Checks

Full suite on net10.0 in both configurations, with no failures:

Configuration Total Failed
Debug 8233 0
Release 8225 0

SanityChecks also passes, and src builds clean on every TFM.

An UNSUBSCRIBE queued behind a subscribe that hasn't been acknowledged
cannot reply first, so a synchronous caller waiting for it blocked for
the whole sync timeout and then returned or threw RedisTimeoutException,
depending on which timer ran out first. main doesn't wait here; nor
does v4 now. The unsubscribe is still sent as an ordinary command, so a
declined or timed-out one is still retried; async callers still await it.

The test's sync timeout is now far above the async one, so the old
behaviour fails every time rather than only on a slow runner.
@mgravell
mgravell merged commit 079192e into v4 Dec 4, 2026
3 checks passed
@mgravell
mgravell deleted the marc/v4-subscription-restoration-test branch December 4, 2026 16:49
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