dotnet: release oversized JSON-RPC receive buffers#2047
Open
adirh3 wants to merge 2 commits into
Open
Conversation
Bound the reusable receive buffer after a completed large frame while preserving any carried bytes for the next frame. Add a regression test that verifies the next read does not retain a multi-megabyte buffer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Bounds retained .NET JSON-RPC receive buffers after processing oversized frames.
Changes:
- Adds a 1 MiB retention threshold while preserving carried bytes.
- Adds a regression test for oversized frames.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
dotnet/src/JsonRpc.cs |
Shrinks oversized receive buffers after parsing. |
dotnet/test/Unit/JsonRpcTests.cs |
Adds oversized-buffer regression coverage. |
| [Fact] | ||
| public async Task JsonRpc_Does_Not_Retain_Oversized_Receive_Buffer() | ||
| { | ||
| using var receiveStream = new FrameThenEofStream(CreateResponseFrame(2 * 1024 * 1024)); |
Author
There was a problem hiding this comment.
Addressed in ec5ff68. The regression now keeps the stream open, forces a second valid response to be coalesced into the same read as the oversized frame, verifies that carried response is processed, and then asserts the subsequent read buffer is bounded. The focused test passes on net8.0 and net472; all 163 .NET SDK unit tests pass on net8.0.
Keep the receive stream open, coalesce a second valid response with the oversized frame, and verify both carried-message processing and the subsequent bounded read buffer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
The .NET JSON-RPC read loop reuses the largest receive buffer for the lifetime of the connection. A single multi-megabyte frame therefore remains rooted while the loop waits for the next message.
Fix
After a completed frame is parsed, replace receive buffers larger than 1 MiB with the smallest buffer needed to preserve any bytes already carried from the next frame. The connection and all sessions remain active.
Validation