Repository navigation
fix(mux-h2): reset a 204/304 backend stream carrying DATA, discard a HEAD response's DATA - #1775
Merged
Merged
Conversation
FlorentinDUBOIS
force-pushed
the
fix/h2-bodiless-response-data-reset
branch
2 times, most recently
from
October 2, 2026 02:55
9754727 to
c0b0290
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
…1778) When an H2 backend sent a header section without END_STREAM and without `content-length`, `pkawa::handle_header` added `Transfer-Encoding: chunked` and framed the response chunked for an H1 client, including for a 1xx, a 204, a 304 and a response to HEAD. These have no content by definition (RFC 9110 §6.4.1), and RFC 9112 §6.1 forbids the field in a 1xx or 204. A 1xx never completed either, so an H1 client read a chunked 103 and never the final response. Such a response now gains no framing: - A 1xx is complete at its head, like kawa's H1 parser does it, and the final response follows on the same stream. - A 204, a 304 or a response to HEAD stays open until the backend ends its stream with an empty DATA frame or a trailer HEADERS frame (RFC 9113 §5.1, §8.1). That END_STREAM ends the response for every frontend: an H1 client reads the head alone, and an H2 client receives END_STREAM. Marked complete at its head, as a response to HEAD already was on `main`, the H2 client stream was retired without END_STREAM, and the backend stream was reset while its trailer HEADERS was in flight. The closed-stream check then answered with GOAWAY(STREAM_CLOSED) for the whole backend connection. Keeping the stream open until END_STREAM needs no reset and no memory of reset streams. One trade-off: a backend that never ends such a stream is bounded by the stream timeout, as for any other response. - A `content-length` is removed from a 1xx or a 204, where a server MUST NOT send it, and kept on a 304 or a response to HEAD (RFC 9110 §8.6). - A `:status 101`, which HTTP/2 does not support (RFC 9113 §8.6), is now a stream error (PROTOCOL_ERROR) answered 502. It used to reach the H1 upgrade path, which closed the session. DATA carrying a payload on a 204, a 304 or a response to HEAD is still forwarded. That is #1772, handled by #1775. Tests: - `a_bodiless_h2_response_gains_no_transfer_encoding_towards_an_h1_client` (`h1.rs`): head bytes and completion for 103, 204, 304 and HEAD, with and without `content-length`, plus a GET 200 control. - `a_101_response_is_a_stream_protocol_error` (`pkawa.rs`). - e2e in `e2e/src/tests/h2_security_header_injection.rs`: - `test_h2_bodiless_response_head_has_no_transfer_encoding` - `test_h2_bodiless_response_ends_the_h2_client_stream`: 204, 304 and HEAD, each ended by trailers or by an empty DATA frame. - `test_h2_bodiless_response_end_keeps_the_backend_connection`: a second stream on the same backend connection, no GOAWAY or RST_STREAM towards the backend. - `test_h2_backend_interim_response_reaches_the_client`: 103 then 200, to an H1 and an H2 client. - `test_h2_backend_101_is_a_bad_gateway` Documented in `lib/src/protocol/mux/LIFECYCLE.md` §8.4 and `CHANGELOG.md`. Fixes #1776 Signed-off-by: Florentin Dubois <[email protected]>
A response to HEAD, a 204 or a 304 has no content (RFC 9110 section 6.4.1), and DATA carrying a payload makes it malformed (RFC 9113 section 8.1.1), but handle_data_frame forwarded that payload: an H1 client read it after the head, with a chunk-size line under chunked framing, as the start of the next response. content_length_exempt skips the content-length checks for these responses. handle_data_frame now resets the backend stream with PROTOCOL_ERROR before the payload is queued, so it never reaches the client. Repoint the h2.rs citations of doc/h2_mux_internals.md the insertion moved. Closes #1772 Signed-off-by: Florentin Dubois <[email protected]>
A response to HEAD only SHOULD NOT carry content (RFC 9110 section 9.3.2), unlike a 204 or a 304, which cannot (sections 15.3.5, 15.4.5). handle_data_frame now resets the backend stream only for a 204 or a 304, counted in h2.bodiless_response_data_reset, and drops the payload of a response to HEAD from the end of the stream buffer without queueing it. Kept behind storage.head, a payload larger than the buffer would remove READABLE from the backend connection before its END_STREAM. Such a stream stays linked until the backend's END_STREAM (#1776), so its DATA reaches these branches whether it arrives with the head or later. A frame-level test drives handle_data_frame through the reset, the discard and the forwarding of a GET 200. The e2e tests cover 204, 304 and HEAD with HEADERS and DATA in one write or apart, and HEAD with 20, 60 and 200 KB of DATA to an H1 and an H2 client and beside a second stream of the same backend connection. The raw H2 mock gains a single-write mode and honours sozu's flow-control windows. Repoint the h2.rs citations of doc/h2_mux_internals.md. A trailer HEADERS frame after the reset of a 204 or a 304 still gets a GOAWAY for the whole backend connection until #1784 lands. Refs #1772 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-bodiless-response-data-reset
branch
from
October 2, 2026 04:44
c0b0290 to
2ce0724
Compare
…nse-data-reset Resolve doc/h2_mux_internals.md: the pinned h2.rs code blocks are re-pinned to the merged file's line numbers. Signed-off-by: Florentin Dubois <[email protected]>
…nse-data-reset Resolve doc/h2_mux_internals.md: the pinned h2.rs code blocks are re-pinned to the merged file's line numbers. Signed-off-by: Florentin Dubois <[email protected]>
…nse-data-reset Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
…TA is ignored (#1807) The CHANGELOG entry and `lib/src/protocol/mux/LIFECYCLE.md` §8.4 from #1775 said that a trailer HEADERS frame a backend sends after the PROTOCOL_ERROR reset of a 204 or a 304 answers GOAWAY(STREAM_CLOSED) for the whole backend connection "until #1784 lands". #1784 is merged, so this PR checks that claim and rewrites the text. What the test shows: - On `2ce07244` (#1775's head before #1784), a trailer in **one HEADERS frame** was already ignored. The reset-stream branches from #1753 cover it, so the GOAWAY(STREAM_CLOSED) described there did not happen. - What did fail before #1784 was a trailer block **split over a CONTINUATION frame**: the CONTINUATION was taken for a standalone frame and answered GOAWAY(PROTOCOL_ERROR), ending every stream of the backend connection. - On `main`, both are ignored (RFC 9113 §5.1) and the backend connection stays up. Test: `a_trailer_after_the_reset_of_a_204_carrying_data_is_ignored` (`lib/src/protocol/mux/h2.rs`). It sends a 204 without END_STREAM, then DATA without END_STREAM, which is reset with PROTOCOL_ERROR. Then it sends the trailer block, once in one frame and once split over a CONTINUATION frame. For both, it asserts no GOAWAY, no RST_STREAM, and that the backend connection is still in `H2State::Header`. - Red on `2ce07244`: `split=true: ... got [(7, 0, 0, [0, 0, 0, 0, 0, 0, 0, 1])]`. The unsplit row passes there. - Red on this branch with the `pending_discarded_block` store in `ConnectionH2::handle_read` removed, with the same failure. - Green on this branch. Docs: the CHANGELOG entry for #1772 and `LIFECYCLE.md` §8.4 now describe the current behaviour and what changed with #1784, in place of the "until #1784 lands" known limitation. No production code changes. Commands run: - `cargo build --locked --all-features`: ok - `cargo clippy --all-features`: ok - `cargo test --locked --all-features -p sozu-lib --lib`: 1547 passed - `python3 .github/scripts/check_doc_citations.py --root .`: ok, also with `--base origin/main` - `cargo +nightly fmt --all -- --check`: ok `cargo clippy -p sozu-lib --all-targets --all-features -- -D warnings` fails only on the existing `chunks_exact(13)` in `h2.rs` tests, which is already on `main` (`chunks_exact_to_as_chunks`, local clippy 1.99). This PR doesn't touch it. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
Bring in the squash of this branch's base, #1789, with #1775, #1798 and #1802. The squash carries the same changes as the base branch head this branch had merged, so lib/src/protocol/mux/mod.rs, lib/src/protocol/mux/LIFECYCLE.md, doc/lifetime_of_a_session.md, e2e/src/tests/tls_tests.rs and CHANGELOG.md are resolved by keeping this branch's edits to that content over main: the net change of this branch against origin/main is the same as it was against the base branch head. The CHANGELOG keeps one copy of the #1779 entry and one blank line between entries. Re-pin the `readable()`, `writable()` and `flush_output_to_socket()` code blocks of doc/h2_mux_internals.md to their lines in the merged h2.rs. Signed-off-by: Florentin Dubois <[email protected]>
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.
A response to HEAD, a 204 or a 304 has no content (RFC 9110 §6.4.1), but
ConnectionH2::handle_data_frameforwarded a DATA payload on it. An H1 client read it after the head as the start of the next response, and an H2 client received it as DATA.h2.bodiless_response_data_reset. An H1 client that was already sent the head sees the connection close; one that was not gets a 502.With #1778, such a backend stream stays linked until its END_STREAM, so its DATA reaches these branches whether it arrives with the head or later.
Known limitation: after the PROTOCOL_ERROR reset of a 204 or a 304, a trailer HEADERS frame the backend had already sent on that stream still triggers a GOAWAY that ends every stream of the backend connection. This lasts until #1784 lands.
Tests:
a_backend_response_content_is_forbidden_for_204_and_304_and_discarded_for_head(h2.rs) pins the classifier.a_204_response_carrying_data_resets_its_backend_stream_and_a_head_response_discards_it(h2.rs) driveshandle_data_framethrough three cases:e2e/src/tests/h2_security_header_injection.rs:test_h2_bodiless_response_data_never_reaches_h1_client: 204, 304 and HEAD, with HEADERS and DATA in one write or 200 ms apart.test_h2_head_response_with_large_data_completes: HEAD with 20, 60 and 200 KB of DATA, to an H1 client with a keep-alive follow-up and to an H2 client.test_h2_head_response_with_large_data_keeps_the_backend_connection: HEAD with 20 KB on stream 1 and a GET on stream 3 over one backend connection.Documented in
lib/src/protocol/mux/LIFECYCLE.md§8.4,doc/configure.mdandCHANGELOG.md.Fixes #1772