Repository navigation
Close three dispose/connect/topology windows behind intermittent CI failures - #3386
Merged
Merged
Conversation
…gnises it GetOrCreateBridge created the bridge - which starts connecting - and only then published it to the interactive/subscription field. Against a fast server, or with the creating thread descheduled, the handshake could complete in that gap, and OnFullyEstablished identifies the connection by comparing its bridge with those fields: an interactive connection not yet in `interactive` skipped its per-connection setup, including the maintenance-notification reconcile. That left a refused `Enabled` connection usable, and a RESP2 downgrade reported as having notifications - the intermittent MaintenanceOptInClientTests failures on the Windows CI job. Publish first, and connect only the bridge that won the publish; a lost race now never opens a connection only to close it again. Verified by widening the gap with a 200ms delay after TryConnect: before, 7 of the 42 MaintenanceOptInClientTests fail every run (exactly the set seen in CI); after, none do.
Member
Author
|
Another intermittent Windows failure on
var quits = new Task[2 * servers.Count]; // read outside the lock
lock (servers)
{
// ... quits[index++] = server.Close(...), twice per server
}A server added between that read and the lock (here, presumably while the redirect is still being resolved during dispose) overruns the array, and dispose throws. The fix is to size the array inside the lock. The code is old, so nothing recent introduced it; recent changes have only made the window easier to hit. |
The task array was sized from servers.Count before taking lock(servers), and filled inside it. A server added in between - e.g. a redirect still being resolved while the multiplexer disposes - overran the array, and dispose threw IndexOutOfRangeException (seen intermittently in UnroutableRedirectUnitTests.UnroutableRedirectDoesNotInventAnEndpoint on the Windows CI job). Read the count inside the lock instead.
CLUSTER SLOTS is lock-free in the in-process server: it counted every node's ranges, rented an array of that size, then filled it from a second read. When the topology changed in between - a test's Migrate merging two ranges back into one while the client's own reconfigure was asking - the array kept a trailing nil element, the writer threw "Array element cannot be nil", and the client's connection faulted (EndpointPruningUnitTests.NodeCarryingSubscriptionsIsNotPruned on the Ubuntu CI job). Snapshot each node's ranges once and size from that.
mgravell
added a commit
that referenced
this pull request
Dec 3, 2026
* Docs: why WithRetry has no retrying batch, and what to use instead (#3388) A batch's one guarantee is an uninterrupted run, which a retry would break: a batch cannot be replayed as a unit (some of it may have applied), and re-issuing just the failed element would reorder it. Document that, and the alternatives: pipelined commands on the retrying database for independent work (each retried by its own category), a retrying transaction for all-or-nothing, and a plain batch where the uninterrupted run is what matters. Closes #3370. (cherry picked from commit 5e2e8e4) * Stabilize two racy tests: keyspace notification counting, and the drain-cap MOVING test (#3393) PubSubKeyNotificationTests counted an event in the total before counting its key. Multi-node notifications arrive on several reader threads, so the last event could complete the run while another, already in the total, had not yet counted its key: the per-key check came up one short (expected 51, actual 50). Count the key first. MovingWaitsForSlowCommandsThatFitInsideTheDrainCap needs exactly one 3s command in flight, but SetLatency slowed every command, and the in-process server answers one at a time: a background INFO ahead of the PING pushed the PING's reply to ~6s, past the 5s drain cap, so the recycle failed it. Add a SetLatency overload that holds a single command, and slow only the PING. (cherry picked from commit f5bf0c3) * Resp3DowngradeTests: keep publishing until the restored subscription receives (#3396) The test published once, straight after the interactive connection came back as RESP2. The subscription is restored separately (with a dedicated connection, on a connection of its own), and a message published before that SUBSCRIBE lands is not delivered, so on a slow runner the test waited 10s for a message that was never coming. It now publishes every 250ms until one arrives, still within 10s, so a subscription that is never restored still fails it. (cherry picked from commit e56835e) * Port main's small 3.5.0 fixes and test hardening to v4 - #3374 (+#3376): v4 already had the inverted-check fix; its regression test comes over (as #3374 shipped it - #3376's TryAdoptEndpoint rename belongs with #3353) - #3361: v4 already disposes socketless tunnel streams; its regression test comes over - #3386: the toy server's CLUSTER SLOTS snapshot fix; the other two windows are in code v4 replaced (QuitAllServers, PhysicalBridge creation; v4 executors connect lazily) - #3395: already the v4 behaviour (GetConnectionId does not dial) - #3394: not applicable; the test it fixes went with the old core
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 the intermittent Windows CI failures on
maininMaintenanceOptInClientTests. A different test in that class has failed on every push since this morning:EnabledFailsAgainstAServerThatRefuses,AutoIsOffWhenTheServerDowngradesToResp2andEnabledFailsWhenResp2WasOurOwnChoice(RESP3, mostly net481).Cause
GetOrCreateBridgecreated the bridge, which starts connecting straight away, and only then published it to theinteractive/subscriptionfield.OnFullyEstablishedidentifies a connection by comparing its bridge with those fields. Against a fast server (the in-process test server has no socket latency), or with the creating thread descheduled on a busy runner, the handshake can complete inside that gap. The interactive connection then isn't recognised asinteractiveand skips its per-connection setup, which includesReconcileMaintenanceNotifications. That accounts for both failure shapes:Enabledopt-in is never acted on, so the connection stays usable ("the connection should not have stayed usable");MaintenanceNotificationsActivereadstrue.The race dates from #3264. Nothing about it changed recently; something has presumably shifted CI timing enough to expose it.
Change
Publish first, and connect only the bridge that won the publish. A bridge that loses the race is disposed without ever having connected, rather than opening a connection only to close it again. Before it connects, a published bridge is in the same "connecting" state it would be in just after starting to connect, so callers that find it early see nothing new.
Verification
I widened the gap locally with a temporary 200ms delay after
TryConnect:MaintenanceOptInClientTests(42)main+ delayWithout the delay, all
*UnitTestsplus the maintenance classes pass on net10.0 (1392) and net481 (1375), and the library builds with 0 warnings across all TFMs. I haven't added a deterministic regression test, because that would need a timing hook in production code. The existing class covers it once the window can't open.Also:
QuitAllServerssized its array outside the lockThe second intermittent Windows failure on
main(UnroutableRedirectUnitTests.UnroutableRedirectDoesNotInventAnEndpoint,IndexOutOfRangeExceptionfromQuitAllServersduringDisposeAsync) is the same kind of window. The task array was sized fromservers.Countbefore takinglock (servers)and filled inside it, so a server added in between (here, a redirect still being resolved during dispose) overran it. It's now sized inside the lock, which is the lock that additions take. The code is old; recent changes have only made the window easier to hit.UnroutableRedirectUnitTestspasses 3/3 locally, and all 1313*UnitTestspass on net10.0.Also: the test server's
CLUSTER SLOTScould reply with a nil elementA third intermittent failure, this time in the in-process test server rather than the library (
EndpointPruningUnitTests.NodeCarryingSubscriptionsIsNotPrunedon Ubuntu, from this PR's own CI run). The server answersCLUSTER SLOTSwithout taking its lock. It counted every node's slot ranges, rented an array of that size, and then filled it from a second read. AMigratefrom the test that merged two ranges back into one, landing while the client's own reconfigure was asking, left a trailing nil element. The writer then threwArray element cannot be nil, and the client's connection faulted. The server now snapshots each node's ranges once and sizes the reply from that. All 1313*UnitTestspass twice in a row on net10.0.