Limit reassembled stream message size - #3489
Merged
Merged
Conversation
Reject a fragmented stream message when its accumulated payload exceeds max_body_size. Release buffered fragments and close the stream with EMSGSIZE. Cover the boundary and rejection paths through a complete client/server RPC stream.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens bRPC streaming RPC framing by enforcing max_body_size on reassembled (fragmented) stream messages, preventing unbounded accumulation across continuation frames and rejecting oversized payloads with EMSGSIZE.
Changes:
- Enforce an accumulated-size cap for fragmented stream DATA frames in
Stream::OnReceived, closing the stream withEMSGSIZEwhen the reassembled message would exceedmax_body_size. - Add an end-to-end client/server unit test that validates (1) acceptance exactly at the limit and (2) rejection just over the limit, using stream segmentation to force fragmentation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/brpc/stream.cpp |
Adds a per-DATA-frame constant-time check that prevents _pending_buf from growing beyond FLAGS_max_body_size, and closes the stream with EMSGSIZE while releasing pending fragments. |
test/brpc_streaming_rpc_unittest.cpp |
Adds an integration-style test covering the boundary (64 bytes) and over-limit (65 bytes) behaviors under forced fragmentation via stream_write_max_segment_size. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
LGTM |
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.
What problem does this PR solve?
Issue Number: N/A
Problem Summary:
Each stream data frame is bounded by
max_body_size, but continuation framescan be accumulated into a message larger than that limit.
What is changed and the side effects?
Changed:
max_body_size.EMSGSIZEwhen theaccumulated payload exceeds the limit.
RPC stream.
Side effects:
max_body_sizeare now rejected instead of being accumulated without abound.
Check List: