Skip to content

Reduce read-ahead buffer allocation in WebSocket keep-alive tests - #136917

Merged
rzikm merged 2 commits into
dotnet:mainfrom
rzikm:rzikm/websocket-long-delay-abort
Nov 4, 2026
Merged

rzikm merged 2 commits into
dotnet:mainfrom
rzikm:rzikm/websocket-long-delay-abort

Conversation

@rzikm

@rzikm rzikm commented Nov 3, 2026

Copy link
Copy Markdown
Member

Reduce ReadAheadWebSocket's scratch receive buffer from 64 MiB to 4 KiB. Its existing callers exchange 1-byte and 6-byte messages, so allocating 128 MiB across the two endpoints is unnecessary. The helper already supports partial receives and queues received data separately.

This is test-only allocation hardening. The keep-alive interval, Pong timeout, and assertions are unchanged. It is not a proven resolution of the historical keep-alive CI failure.

A focused BenchmarkDotNet allocation benchmark measured 64 MiB buffers at 4.723 ms and 65,536.68 KiB allocated, versus 4 KiB buffers at 0.664 us and 4.02 KiB allocated. Under a 192 MiB managed heap limit, three original test runs triggered 1, 2, and 2 Gen-2 collections; three changed runs triggered none. These measurements do not establish that GC caused the CI failure.

Validation

Commands ran from the isolated worktree through an owned X: shortcut, using Debug libraries/tests with Release CoreCLR. Full CI Release-library configuration was not run.

  • X:\build.cmd clr+libs -rc release — passed; clean baseline, zero warnings/errors.
  • X:\.dotnet\dotnet.exe build src\libraries\System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj /t:test /p:RuntimeConfiguration=Release /p:Outerloop=true "/p:XUnitOptions=-method System.Net.WebSockets.Client.Tests.KeepAliveTest_*Loopback.KeepAlive_LongDelayBetweenSendReceives_Succeeds -maxthreads 2" — passed: 10 tests, zero failures or skips.
  • X:\.dotnet\dotnet.exe build src\libraries\System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj --no-restore /t:test /p:testnobuild=true /p:RuntimeConfiguration=Release — passed: 685 total, 663 passed, 22 existing skips, zero failures.

Note

This PR description and change were prepared with GitHub Copilot.

rzikm and others added 2 commits November 3, 2026 14:36
Use a 4 KiB read-ahead buffer instead of allocating 64 MiB per endpoint for the long-delay test. Preserve the existing heartbeat interval, Pong deadline, and state assertions.

Cover empty messages and receive-buffer boundaries across the loopback variants. The reduced allocation removes avoidable GC pressure; it does not establish that the historical CI abort is eliminated.

Co-authored-by: Copilot App <[email protected]>
Keep the change scoped to reducing the existing helper buffer, as requested.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@rzikm
rzikm merged commit 1e8e623 into dotnet:main Nov 4, 2026
96 of 98 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants