Skip to content

Limit reassembled stream message size - #3489

Merged
chenBright merged 1 commit into
apache:masterfrom
wasphin:fix-stream-reassembly-limit
Aug 26, 2026
Merged

Limit reassembled stream message size#3489
chenBright merged 1 commit into
apache:masterfrom
wasphin:fix-stream-reassembly-limit

Conversation

@wasphin

@wasphin wasphin commented Aug 25, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: N/A

Problem Summary:

Each stream data frame is bounded by max_body_size, but continuation frames
can be accumulated into a message larger than that limit.

What is changed and the side effects?

Changed:

  • Limit the accumulated payload of a fragmented stream message to
    max_body_size.
  • Release pending fragments and close the stream with EMSGSIZE when the
    accumulated payload exceeds the limit.
  • Cover the boundary and rejection behavior through a complete client/server
    RPC stream.

Side effects:

  • Performance effects: one constant-time size check per stream data frame.
  • Breaking backward compatibility: fragmented stream messages larger than
    max_body_size are now rejected instead of being accumulated without a
    bound.

Check List:

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with EMSGSIZE when the reassembled message would exceed max_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.

@wwbmmm

wwbmmm commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

LGTM

@chenBright chenBright left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenBright
chenBright merged commit 4047c4e into apache:master Aug 26, 2026
15 checks passed
@wasphin
wasphin deleted the fix-stream-reassembly-limit branch August 26, 2026 03:31
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.

4 participants