Skip to content

test(desktop): stop flaky gateway SSE stream-count race by retaining response refs - #994

Merged
Astro-Han merged 1 commit into
mainfrom
test/gateway-sse-flaky-response-ref
Jul 14, 2026
Merged

test(desktop): stop flaky gateway SSE stream-count race by retaining response refs#994
Astro-Han merged 1 commit into
mainfrom
test/gateway-sse-flaky-response-ref

Conversation

@Astro-Han

Copy link
Copy Markdown
Contributor

Summary

open-gateway.test.ts › "rejects excess SSE streams" was intermittently failing at assert.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 each AbortController, discarding the Response. 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-initiated req '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

  • Reproduced on main under 2× CPU load: full-file loop 7/12 failed (2 !== 10, 4 !== 10). Instrumented openSessionEventStream/removeEventClient and confirmed all 10 streams registered, then req close … aborted=true tore them down before the assertion; instrumentation reverted.
  • After fix, same load: affected file 20/20 pass; full desktop main suite (2528 tests) 10/10 pass.
  • Swept other SSE tests — abuse-contract is a static source scan, runtime/headless parse mock streams — none share this class.

Root cause

undici GC-aborts unconsumed fetch response bodies; the test dropped its Response refs, so GC (load-sensitive) closed registered streams before the count assertion.

…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
@Astro-Han
Astro-Han merged commit b7460c2 into main Jul 14, 2026
3 checks passed
@Astro-Han
Astro-Han deleted the test/gateway-sse-flaky-response-ref branch July 25, 2026 15:14
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.

Flaky test: open-gateway "rejects excess SSE streams" intermittently reads 7 active streams instead of 10

1 participant