sahvx655-wq commented on code in PR #3772:
URL: https://github.com/apache/brpc/pull/3772#discussion_r4684470026
##########
src/brpc/policy/http2_rpc_protocol.cpp:
##########
@@ -624,7 +644,21 @@ ParseResult H2Context::Consume(
LOG(ERROR) << "Invalid frame type=" << (int)frame_head.type;
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
}
- H2ParseResult h2_res = (this->*handler)(it, frame_head);
+ // A header block is decoded against the connection-wide HPACK
+ // context, so the frames carrying it have to arrive uninterrupted
+ // (RFC 9113 section 6.10). Without this, a CONTINUATION extends a
+ // header block that END_HEADERS already closed, and blocks of two
+ // streams can be decoded out of order.
+ H2ParseResult h2_res = CheckHeaderBlockContinuity(frame_head);
Review Comment:
Fixed in 6186cca, the check now runs straight after ConsumeFrameHead() so
the frame type no longer matters to it. The consequence you describe is right:
behind FindFrameHandler(), an unregistered type arriving inside an open block
fell through to the handler == nullptr branch, which returns
PARSE_ERROR_ABSOLUTELY_WRONG and writes nothing, so the peer had its socket
dropped with no GOAWAY and no error code at all.
I pinned that in the test rather than trusting the ordering to stay put:
frame type 0x63 sent inside stream 7's open header block now has to put a
GOAWAY on the wire, and the test reads the frame back off the fixture pipe and
checks the error code is PROTOCOL_ERROR. Reverting just the reorder makes it
fail with bytes_in_pipe 0, which is the silent path you found.
##########
src/brpc/policy/http2_rpc_protocol.cpp:
##########
@@ -624,7 +644,21 @@ ParseResult H2Context::Consume(
LOG(ERROR) << "Invalid frame type=" << (int)frame_head.type;
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
}
- H2ParseResult h2_res = (this->*handler)(it, frame_head);
+ // A header block is decoded against the connection-wide HPACK
+ // context, so the frames carrying it have to arrive uninterrupted
+ // (RFC 9113 section 6.10). Without this, a CONTINUATION extends a
+ // header block that END_HEADERS already closed, and blocks of two
+ // streams can be decoded out of order.
+ H2ParseResult h2_res = CheckHeaderBlockContinuity(frame_head);
+ if (h2_res.is_ok()) {
+ if (frame_head.type == H2_FRAME_HEADERS ||
+ frame_head.type == H2_FRAME_CONTINUATION) {
+ _expect_continuation_stream_id =
+ (frame_head.flags & H2_FLAGS_END_HEADERS)
+ ? 0 : frame_head.stream_id;
+ }
+ h2_res = (this->*handler)(it, frame_head);
+ }
Review Comment:
I went through the paths that can reach this and left it publishing the
state before the handler, deliberately. The only way to get a stream-scoped
error out of a HEADERS frame that lacks END_HEADERS is TryToInsertStream()
returning 2 at max_concurrent_streams, and a peer in that position still owes
us the CONTINUATION frames of that block; section 6.10 holds whether or not we
accepted the stream, so a frame for another stream turning up there is the
violation the check exists to catch. Clearing the state on failure would only
move which frame kills the connection, since the CONTINUATION that does arrive
would then be refused as one outside a header block.
For what master already does with that exact sequence: OnHeaders() returns
at the REFUSED_STREAM branch without forwarding the iterator past the fragment,
so the payload is re-read as the next frame head, and a CONTINUATION for a
stream we have just removed logs 'Fail to find stream_id=' in OnContinuation()
and becomes a connection error regardless. The connection is lost either way,
so this patch isn't taking a working case away. The real hole underneath is
that a refused stream's header block never reaches the HPACK decoder, which
desynchronises the dynamic table from the peer's; that's worth fixing, but as
its own change rather than buried in a continuity check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]