Skip to content

test(zero-swift): keep frames that arrive with the WebSocket upgrade response - #49

Merged
tmm merged 1 commit into
mainfrom
swift-nio-upgrade-leftover-bytes
Oct 27, 2026
Merged

tmm merged 1 commit into
mainfrom
swift-nio-upgrade-leftover-bytes

Conversation

@tmm

@tmm tmm commented Oct 27, 2026

Copy link
Copy Markdown
Member

Fixes the flaky slowReaderLargePokeCompletesOnOneConnection e2e failure (seen on #43: "received a binary poke chunk without pokeStart").

Cause: NIOTransport, the test-only Linux transport, used NIO's default leftOverBytesStrategy = .dropBytes. WebSocket frames that arrived in the same TCP read as the 101 response were thrown away. The chaos proxy's throttle batches bytes into 10 ms ticks, so connected and pokeStart could land in that read, and the client then received the poke's binary chunk with nothing before it. The CI server log agrees: the client closed 20 ms after initConnection, and it had never handled connected ("Failed to connect").

Fix: set leftOverBytesStrategy = .forwardBytes so those bytes go to the WebSocket decoder.

Scope: test harness only. Apps use URLSessionTransport, so no changeset.

Verification:

  • A scratch repro had a ws server send two text frames right after the upgrade and a binary frame 100 ms later. Before the fix, 20/20 connections through the throttled proxy and 6/20 direct connections lost the text frames. After it, 40/40 got all three.
  • Full --filter E2ETests: 19/19 pass.

…response

NIOTransport, the e2e tests' Linux transport, used NIO's default
leftOverBytesStrategy (.dropBytes), so WebSocket frames in the same TCP
read as the 101 response were discarded. Behind the chaos proxy's
throttle, connected and pokeStart could share that read; the client then
saw the poke's binary chunk alone and stopped with "received a binary
poke chunk without pokeStart" (the flaky
slowReaderLargePokeCompletesOnOneConnection failure). Forward the bytes
to the WebSocket decoder instead.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8
Co-authored-by: tmm <tmm@tmm.dev>
@tmm
tmm merged commit fd1bf34 into main Oct 27, 2026
9 checks passed
@tmm
tmm deleted the swift-nio-upgrade-leftover-bytes branch October 27, 2026 16:22
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.

2 participants