Repository navigation
fix(mux-h2): end a chunked H1 body with the last chunk before H2 trailers - #1724
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 30, 2026 12:40
FlorentinDUBOIS
force-pushed
the
fix/h2-h1-trailer-last-chunk
branch
from
September 30, 2026 13:22
f27aba5 to
d81ffd1
Compare
…lers
pkawa::handle_trailer closed an H2 trailer block with a single Flags
block without end_body, the marker for which kawa's H1 serializer writes
the last chunk. An H2 request with trailers therefore reached an H1
backend as 5\r\nhello\r\ngrpc-status: 0\r\n\r\n, the first trailer
field standing where RFC 9112 section 7.1 puts the last chunk, which
breaks request framing on a keep-alive backend connection. A trailer
block with no field left (empty, or every field elided) gave
5\r\nhello\r\n\r\n, a chunked body that never ends. A response from an
H2 backend to an H1 client lost its last chunk the same way.
Once the block is accepted, queue Flags { end_body: true } before the
trailer fields, the shape kawa's H1 parser gives a chunked trailer
section; a refused block adds no marker. H2BlockConverter ignores
end_body, so an H2 peer is unaffected.
Closes #1722
Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-h1-trailer-last-chunk
branch
from
September 30, 2026 15:34
d81ffd1 to
a45bbf0
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 1, 2026
…1731) Closes #1730 ## Change H2→H1: drop the trailer fields of a Content-Length-framed message instead of writing them after the body. HTTP/1.1 carries a trailer section only with chunked transfer coding (RFC 9112 §7.1.2), and a message framed by Content-Length ends with its last body byte (RFC 9112 §6.3). RFC 9110 §6.5 lets a recipient discard trailers. - `ConnectionH1::drop_length_framed_trailers` (`lib/src/protocol/mux/h1.rs`) runs in `ConnectionH1::writable` before kawa's H1 `prepare`. For a `BodySize::Length` message whose queue ends with a trailer block, it removes the trailer fields and clears `end_header` on the closing flags, so nothing is written after the body. This covers requests to an H1 backend and responses to an H1 client. - Each dropped block logs a `warn!` and increments `h2.trailers_dropped_content_length` at the write. - `pkawa::handle_trailer` still validates, elides and queues the block, so H2 peers keep these trailers and the `h2.trailer.*_elided` counters are unchanged. - Docs: `doc/configure.md` metric row, `lib/src/protocol/mux/LIFECYCLE.md` §8.4, CHANGELOG (Unreleased, Security). #1724 (last chunk before H2 trailers on a chunked H1 body) is merged; this branch is rebased on it. ## Tests - `a_length_framed_message_writes_no_trailer_to_an_h1_peer` (`h1.rs`): request and response, with one trailer field and with none; H1 bytes are exactly `hello`. - `a_length_framed_header_section_is_not_taken_for_trailers` (`h1.rs`). - `a_length_framed_trailer_block_reaches_an_h2_peer` (`converter.rs`): DATA, then HEADERS with END_STREAM holding the trailer field. - `handle_trailer_filters_and_keeps_a_length_framed_block` (`pkawa.rs`): elision counters fire for a length-framed block. - `test_h2_length_framed_request_trailers_keep_h1_backend_framing` (e2e): the backend bytes are split by HTTP/1.1 framing, and the byte after the body starts the next request line. ## Validation - fmt, MSRV clippy, rustdoc `-D warnings`, `cargo test -p sozu-lib --all-features`, fuzz build, and the 4 `check_doc_citations.py` modes all exit 0. - e2e `protocol_pair_matrix` and `h2_security_header_injection` pass. - e2e `trailer`: 21 passed, 1 failed, `test_h1_trailer_field_limit_exceeded_split_closes_backend`. That failure is pre-existing on `main` (H1→H1, chunked body) and is being fixed separately. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 3, 2026
…1809) Audit of the docs, `bin/config.toml` and `os-build/config.toml` against everything merged on `main` from 2026-10-01 to 2026-10-03 (43 commits, #1724 through #1808). Most of the new keys were already documented by their own PRs (`max_connection_attempts`, `h2_stream_refusal_percent`, health check `mode`/`accepted_statuses`, the raised flood defaults, the 16 MiB connection window). This PR fixes what was still stale. | Area | Where | Was | Now | |---|---|---|---| | #1806 | `bin/config.toml`, `os-build/config.toml` answer comments | 503 only for "no backend available"; "504 means the backend timed out" | 503 also when every attempt failed; 504 = connected backend silent or frontend timeout while waiting; connect timeout fails over | | #1806 | `bin/config.toml` `max_connection_attempts` | connect timeout always fails over | a TCP session whose connect times out is closed | | #1806 | `doc/debugging_strategies.md` | 503 after a circuit breaker of 3 failed connections; ERROR log lines, one that no longer exists | `max_connection_attempts` (default 5), `backend.connect.retries_exhausted`, real TCP log levels and text | | #1806 | `doc/configure.md` `front_timeout` / `connect_timeout` rows | "inactivity for a request to connect" | time to establish a backend connection; HTTP fails over, TCP closes; H1 failover bound by `front_timeout` | | #1806 | `doc/configure.md` `client_timeout_during_response`, `backend_timeout`, `http.503.errors` | "connection-level slowness", "circuit breaker" | failover case included; established connection only; attempt budget | | #1806 | `LIFECYCLE.md` backend timer | 504 for any linked stream | established connection only | | #1806 | `cli.rs` help, `doc/configure_cli.md` | "answered 503" | "or a TCP session is closed" | | #1756 | `doc/configure.md` flood metrics | RST lifetime rows described as absolute ceilings; no `window_update_stream0_window` row | floor-and-ratio semantics; row added | | #1756/#1798 | `doc/architecture.md`, `doc/h2_mux_internals.md` | 6 / 13 `H2FloodConfig` thresholds | 14, with `h2_stream_refusal_percent` | | #1756 | `doc/configure_admin_ops.md` | "halve" example 50/25 (old defaults); H2 knobs HTTPS only | 1000/500; HTTP and HTTPS; `h2.flood.stream_refused` | | #1752 | `doc/configure.md` glitch tuning | "1 MiB window ... about 64" frames | 64 KiB stream window, about four | | #1805 | `doc/health_checks.md` | `remove` resets backends to healthy; DOWN logs an error; `load_balancing.rs::BackendList::healthy` | backends keep their last state (see note); warning; `BackendList::select_tiers` in `backends.rs` | | #1805 | `doc/metrics.md` | health-check counters "per cluster" | unlabelled | | #1805 | `doc/configure_cli.md` | no health-check section | short section, `--mode`, `--probe-timeout` vs global `--timeout` | | #1746 | `cli.rs` `--load-balancing-policy`, `bin/config.toml`, proto comment | HRW/MAGLEV key = UDP flow key | UDP affinity key (source IP, or IP and port) | | UDP | `doc/configure.md` | hot upgrade drains flows bounded by idle timeout; `udp.flows.evicted` reasons | soft-stop closes flows at once; listener removal/soft-stop/abort added | | #1770 | `doc/udp_simulation.md` | no per-source limits | in reconfig storms and the invariant list | | #1743 | `doc/lifetime_of_a_session.md` | keep-alive backend always reused | unless its backend was removed | | older | `command.proto` update messages | `h2_stream_shrink_ratio >= 1` | `>= 2`, as validated in `state.rs` | | #1806 | e2e shuffle-sharding doc comment | "three connection attempts" | `max_connection_attempts` (5 by default) | Reported here, not changed in this PR: - `sozu cluster health-check remove` does not reset backends a probe marked DOWN (`remove_health_check_state` skips the reset that `set_health_check_config(None)` does), so they stay out of rotation until the cluster is added again. The doc now describes this. It looks like a code bug. - `sozu top`'s H2 pane reads `h2.flood.violation.{rapid_reset,made_you_reset,ping,settings,priority,continuation}`, which the detector never emits (it emits `rst_stream_pre_response_lifetime`, `ping_window`, ...). Only `glitch_window` matches, and `h2.flood.stream_refused` is not shown. - `h2_flood_detector.rs` comments still refer to a 1 MiB connection window, and the `h2_stream_idle_timeout_seconds` proto comment says "Default: 30" where the value inherits `back_timeout`. - `connections.rejected_per_cluster_ip` is documented as also counting TCP rejections; only the HTTP 429 path increments it. Validation: - `sozu config check` passes on `bin/config.toml`, on a copy with every commented key under review uncommented (global and cluster `max_connection_attempts`, the H2 block, the health check block), and on `os-build/config.toml` with local state/socket paths. Negative controls (`max_connection_attempts = 0`; `expected_status = 200` next to `accepted_statuses`) are rejected. - `cargo +1.93.1 test -p sozu-command-lib --all-features --locked`: 235 passed. - `cargo +1.93.1 test -p sozu --bin sozu --locked`: 124 passed (including the `--load-balancing-policy` help tests). - `cargo +nightly fmt --all --check` and `python3 .github/scripts/check_doc_citations.py --root . --base origin/main` are clean. 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.
Closes #1722
Problem
An H2 request with no
content-lengthis chunked towards an H1 backend. When it ended with a trailer HEADERS frame, the backend read5\r\nhello\r\ngrpc-status: 0\r\n\r\n. The last chunk0\r\n(RFC 9112 §7.1) was missing before the trailer fields, so a strict backend readgrpc-status: 0as an invalid chunk size. On a keep-alive backend connection this breaks request framing. A trailer block with no field left (empty, or every field elided) gave5\r\nhello\r\n\r\n, a chunked body that never ends, so the H1 peer waited for a next chunk. A response from an H2 backend to an H1 client lost its last chunk the same way.Cause
pkawa::handle_trailer(lib/src/protocol/mux/pkawa.rs) closed the trailer block with a singleFlags { end_body: false, end_header: true, end_stream: true }. kawa's H1 serializer writes0\r\nonly for aFlagsblock withend_bodyon a chunked message, so nothing wrote the last chunk.Fix
Once it has accepted the block,
handle_trailernow queuesFlags { end_body: true, end_chunk: false, end_header: false, end_stream: false }before the trailer fields; a refused block adds no marker. That is the block shape kawa's H1 parser gives a chunked trailer section. For a chunked message, kawa's H1 serializer now writes0\r\n, the fields, then the empty line.H2BlockConverterignoresend_body, so H2→H2 is unchanged. H1→H1 was not affected: kawa's parser already queues the marker, andh1_security_tests.rsasserts0\r\nGrpc-Status: 0\r\n\r\n.The code change is one
blocks.insertat the index where the trailer fields start. The docs are updated in the same change:lib/src/protocol/mux/LIFECYCLE.md§9 gets invariant 32, and CHANGELOG Unreleased gets a Security entry.Tests
handle_trailer_follows_the_last_chunk_on_h1(unit,pkawa.rs): runshandle_traileron a chunked request kawa and a chunked response kawa, serializes each withkawa::h1::BlockConverter, and asserts5\r\nhello\r\n0\r\ngrpc-status: 0\r\n\r\n.handle_trailer_with_every_field_elided_ends_the_chunked_body_on_h1(unit,pkawa.rs): same, with every trailer field elided; asserts5\r\nhello\r\n0\r\n\r\n.test_h2_request_trailers_follow_last_chunk_h1_backend(e2e,h2_security_header_injection.rs): an H2 client and a raw H1 backend. It asserts the exact chunked body the backend reads, with agrpc-statustrailer (…0\r\ngrpc-status: 0\r\n\r\n) and with a trailer that is fully elided (…0\r\n\r\n).Both tests were run red with the fix removed:
With the fix they pass.
Interaction with #1720
#1720 (
fix/h2-trailer-forbidden-fields) also toucheshandle_trailer.git merge-treeof the two branches reports no conflict. Its e2e testtest_h2_trailer_forbidden_fields_dropped_h1_backendaccepts the backend bytes with or without the0\r\nlast-chunk line (strip_prefix("0\r\n")), so it passed while this defect was present. Once both PRs land, that optional strip could become a required0\r\n.Validation
cargo +nightly fmt --all --check→ 0cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings→ 0RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked→ 0cargo test -p sozu-lib --all-features --locked→ 0 (1447 passed; after the review follow-up,-- pkawa→ 0, 74 passed)cargo test -p sozu-e2e --locked -- trailer→ 0 (18 passed);-- protocol_pair_matrix→ 0 (28 passed);-- h2→ 0 (268 passed) —trailerrerun after the follow-up → 0 (18 passed)cd fuzz && cargo +nightly fuzz build→ 0check_doc_citations.py--self-test,--root .,--root . --base origin/main,--audit --root .→ 0 each