Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The refused-stream path ignores header-decoding failures, potentially leaving framing and HPACK state desynchronized.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes HTTP/2 refused-stream HEADERS handling and adds regression coverage.
Changes:
- Consume refused HEADERS payloads to preserve framing and HPACK state.
- Add a regression test for frame-buffer consumption.
File summaries
| File | Summary |
|---|---|
test/brpc_http_rpc_protocol_unittest.cpp |
Adds refused-stream consumption regression coverage. |
src/brpc/policy/http2_rpc_protocol.cpp |
Handles refused HEADERS payloads before stream cleanup. |
Review details
Suppressed comments (1)
src/brpc/policy/http2_rpc_protocol.cpp:665
- This also loses the continuation state for a fragmented header block. When
END_HEADERSis absent,OnHeadersstores the partial block insctx; deleting it here makes the required followingCONTINUATIONenter the server-side unknown-stream path and produce a connectionPROTOCOL_ERROR/GOAWAY, even thoughREFUSED_STREAMis intended to leave the connection usable. Keep discard state for refused streams and decode/drain their CONTINUATION frames throughEND_HEADERS.
sctx->OnHeaders(it, frame_head, frag_size, pad_length);
delete sctx;
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+664
to
+665
| sctx->OnHeaders(it, frame_head, frag_size, pad_length); | ||
| delete sctx; |
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: resolve N/A
Problem Summary:
When a HEADERS frame opens a stream past
max_concurrent_streams,H2Context::OnHeadersreturnsRST_STREAM(REFUSED_STREAM)but never consumes that frame's header-block payload. REFUSED_STREAM is a stream error, so the connection stays open andParseH2Messagekeeps parsing; the leftover header-block bytes are then read byConsumeFrameHeadas the next frame head, letting a peer smuggle frames past the h2 framing layer, and the HPACK decoder is left desynced because the refused block was never decoded.OnDataand the client-side unknown-stream branch right below already drain the payload before returning a stream error; only the refused-stream path skipped it.What is changed and the side effects?
Changed:
Decode and consume the refused stream's header block (
sctx->OnHeaders) before deleting the context and returning REFUSED_STREAM, mirroring the two sibling paths. This keeps both the frame parser and the HPACK decoder in sync. Added a regression test intest/brpc_http_rpc_protocol_unittest.cppthat fails before the change (only the 9-byte frame head was consumed, leaving the header block to be misparsed) and passes after.Side effects:
Performance effects: one extra HPACK decode of a header block that is then discarded, only on refused streams.
Breaking backward compatibility: none.
Check List: