Skip to content

test: leave the cancelled stream after it has started, not on a timer - #52

Merged
fylorn merged 1 commit into
devfrom
fix/cancelled-stream-log-race
Sep 24, 2026
Merged

fylorn merged 1 commit into
devfrom
fix/cancelled-stream-log-race

Conversation

@fylorn

@fylorn fylorn commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Root cause of the streaming_client_disconnect_emits_cancelled_gateway_log flake ("gateway_logs cancelled row never landed").

The test disconnected with a 150 ms client timeout. The gateway returns the SSE response only after the API-key middleware, rate limits/budget/access, and routing. When those took longer than 150 ms (a loaded machine), the client left before the stream existed: hyper dropped the handler future, the stream's tail never ran, and no row was written — which is exactly the reported failure. Reproduced deterministically by lowering the timeout to 5 ms (fails after the 10 s wait with the same message).

Fix: the client waits for the response headers — the gateway sends them before it calls the upstream (the upstream call starts on the body's first poll) — then drops the response. The disconnect now always lands on a running stream, which is what the test pins (499 + client_cancelled). The upstream delay goes from 5 s to 60 s so it can never answer first. No retries or sleeps added.

Not changed: a client that leaves during auth/limits/routing still leaves no gateway_logs row. That window is milliseconds and outside what the stream path records today; covering it would need a drop guard in the handler — a separate decision.

Local: the test passes 3/3 with the fix; full integration suite unaffected (test-only change).

🤖 Generated with Claude Code

streaming_client_disconnect_emits_cancelled_gateway_log dropped the
request on a 150 ms client timeout. The gateway returns the SSE response
only after auth, limits and routing; when those took longer than 150 ms
under load, the client left before the stream existed, hyper dropped the
handler, and no gateway_logs row was ever written ("cancelled row never
landed"). Reproduced deterministically with a 5 ms timeout.

The client now waits for the response headers, which the gateway sends
before calling the upstream, and drops the response: the disconnect
always lands on a running stream, which is what the test is about. The
upstream's delay goes from 5 s to 60 s so it can never answer first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit dbce845 into dev Sep 24, 2026
6 checks passed
@fylorn
fylorn deleted the fix/cancelled-stream-log-race branch September 24, 2026 09:50
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