test(desktop): stop flaky gateway SSE stream-count race by retaining response refs - #994
Merged
Merged
Conversation
…response refs The "rejects excess SSE streams" test opened 10 held-open SSE fetches but only kept each AbortController, dropping the Response objects. undici aborts a fetch connection when its unread response body is garbage-collected, so under load (heavier GC) the client tore down already-registered streams before the activeEventStreams assertion ran, intermittently reading 2-7 instead of 10. Retain the whole opened stream (controller + response) through the assertions so the bodies stay reachable and the connections stay open. Product code is correct: the gateway registered all 10 streams and only removed them on client-initiated req 'close'. Refs #993
This was referenced Jul 15, 2026
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.
Summary
open-gateway.test.ts› "rejects excess SSE streams" was intermittently failing atassert.equal(activeEventStreams, 10), reading 2–7 instead of 10 under load (#993).Root cause is in the test, not the gateway. The test opened 10 held-open SSE
fetches but kept only eachAbortController, discarding theResponse. undici aborts a fetch connection when its unread response body is garbage-collected, so under heavier GC (load) the client tore down already-registered streams before the assertion ran. The gateway itself registered all 10 correctly and only removed them on client-initiatedreq 'close'.Fix: retain the whole opened stream (controller + response) through the assertions so the bodies stay reachable and the connections stay open.
Closes #993
Verification
mainunder 2× CPU load: full-file loop 7/12 failed (2 !== 10,4 !== 10). InstrumentedopenSessionEventStream/removeEventClientand confirmed all 10 streams registered, thenreq close … aborted=truetore them down before the assertion; instrumentation reverted.Root cause
undici GC-aborts unconsumed fetch response bodies; the test dropped its
Responserefs, so GC (load-sensitive) closed registered streams before the count assertion.