Repository navigation
refactor(mux-h2): scope the H2 block converter to one kawa.prepare call - #1463
Merged
Merged
Conversation
`ConnectionH2::write_streams` built one `H2BlockConverter` per write pass and held it across the whole per-stream loop. The converter borrows the connection's HPACK encoder out of `HpackState`, so that outstanding `&mut self.hpack` made every `&self` / `&mut self` method uncallable inside the loop: `snapshot_rtts` and `try_recycle_server_stream` were associated functions taking individual field references, and both said so in their own doc comments. Build the converter for exactly ONE `kawa.prepare` call instead. The borrow then lasts two statements rather than the loop, and both functions become ordinary methods — `self.snapshot_rtts(&endpoint, linked_token)`, exactly the shape `doc/h2_mux_internals.md` was already describing, and `self.try_recycle_server_stream(stream, ...)` — dropping five parameters across five call sites. New `converter::H2ConverterPass` carries what has to cross from one stream's `prepare` to the next: the three reusable scratch buffers, MOVED (`Vec` pointer/length/capacity) and never copied, and the RFC 7541 §6.3 dynamic-table-size-update signal, which belongs to the first header block of the pass and to no other. Threading that signal through `reclaim` rather than by hand at each site is what stops a second stream re-emitting the prefix: `emit_pending_size_update_if_new_block` `take()`s it the moment it writes it. The encoder stays in `HpackState` and is re-borrowed per `prepare`, so the HPACK dynamic table remains continuous across the streams of a pass. No behaviour change and no new copy on the write path: the eleven buffer-copying sites in `converter.rs` are the same eleven, and `flush_stream_out` still gathers `IoSlice`s straight out of `kawa.storage.buffer()`. What stays deferred to after the loop is deferred for ordering reasons the comments now state instead of citing the borrow: RST accounting via `freshly_emitted_rsts`, because a MadeYouReset cap trip returns a GOAWAY result that must not preempt the remaining streams' writes; and stream retirement via `completed_streams`, because `try_recycle_server_stream` passes `is_last_stream` as `streams().len() == 1` — the branch that hands the whole remaining overhead pool to one stream — so retiring inline would let a later completer of the same pass drain it while other streams are still live. Tests: `one_write_pass_prefixes_its_first_header_block_only_and_shares_one_encoder` pins both cross-stream properties on the wire — two streams in one pass, the §6.3 prefix on the first block only, one peer decoder replaying both blocks, and, as the negative half, a fresh decoder that must FAIL on the second because it indexes dynamic-table entries only the first block created. Seen red both ways: dropping the `pending_table_size_update` line from `reclaim` makes stream 3 re-emit the prefix, and handing the pass a fresh encoder makes the last assertion fail. `write_pass_property::qc_one_write_pass_prefixes_its_first_header_block_only` generalises the stream count (2..=5) and the advertised table size with `quickcheck`. Neither property is visible to `converter.rs`'s own unit tests, which drive one converter over one kawa. Docs: LIFECYCLE.md gains invariant 25 for the two properties, invariant 17's two approximate `~NNNN` line references become exact citations of the three bucket-decrement sites, and 75 citation endpoints across LIFECYCLE.md and doc/testing.md are renumbered to the lines their text moved to, each by an exact `difflib` mapping over the diff's `equal` blocks so the new line's text is identical to the old by construction. Four became symbol citations instead, because their new numbers collided with numbers the base documents cite for different code and the drift rule keys on the citation, not on where it sits: the `EndStreamAction::Reconnect` `StreamState::Link` transition, the four `self.now = context.now;` entry points (one enumeration, so all four moved together), and the `FcStallAction::Arm` branch of `write_streams`. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 02:29
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.
Step 7 of the H2 sans-io extraction. Follows #1440.
write_streamsbuilt oneH2BlockConverterand held it across the wholeper-stream write loop, which forced every function it touched to be an
associated function taking individual field references instead of a method —
because a
&selfreceiver would have conflicted with the converter's borrow.This scopes the converter to one
kawa.preparecall. The borrow no longerspans the loop, so those functions become ordinary methods.
What changes
H2BlockConverteris constructed perkawa.preparecall rather than once per pass.snapshot_rttsbecomes a&selfmethod (was an associated fn takingposition,socket,endpoint,linked_token).try_recycle_server_streambecomes a&mut selfmethod (was an associated fntaking
position,bytes,streams, …).hpack_state.rsgains one line inshrink_converter_buffers.Documentation the rebase made mandatory
mainhad added prose explaining why those two were free functions:Both statements are false once this changeset lands — it is precisely the
constraint they describe that it removes. They are rewritten rather than left:
This is the repository's dominant defect class — a justification comment that
outlives its reason — caught because the rebase forced the two sides together.
Rebase notes (this branch is old)
Three of its four original commits are already on
mainas squash merges andwere dropped with
--onto, each verified by content, not by commit message:f76c8eb3h2_drain.rsblob identical to main's3be8c888h2_header_reassembly.rsblob identical to main'sf4d49696h2_flood_detector.rsdiffers +319/−34 — #1418 privatisedH2FloodConfigbehind accessors. Main's version won; the branch's older copy was not resurrectedIndependent check that nothing was resurrected: the merged
## [Unreleased]section adds exactly one bullet over
main, with zero duplicates and noheading drift.
47 conflicts against the final base. 45 were numbers-only —
mainand thisbranch renumbering the same citations from a shared ancestor — resolved by
remapping every
h2.rs:NNNthrough adifflib.SequenceMatchermap into thefinal merged file and text-verifying each against the pre-rebase tree, zero
unmapped. Two were genuine prose, both resolved in
main's favour: #1434 hadconverted the
compute_stream_byte_totalspinned block to a symbol citation,and added prose justifying a retained line for
generate_access_log.Also re-derived, and not mentioned in the commit message:
doc/README.md'ssyntax example (
hpack_state.rs:121-131→122-132,:139→:140) and 11pinned blocks in
doc/h2_mux_internals.md, two of which had their contentchanged by this changeset and were re-quoted rather than renumbered. A collision
check for the #1447 reused-number shape found none.
Replay faithfulness, counted: 409/409 added
h2.rslines, 116/116converter.rs, 5/5hpack_state.rs, 36/36 CHANGELOG — nothing lost, nothing new.Verification
CI's own per-crate commands,
FLAGS='--no-default-features --features crypto-ring,opentelemetry,splice,simd':cargo +nightly fmt --all -- --checkcargo build --locked $FLAGScargo clippy --all-targets --locked $FLAGS -- -D warningscargo test -p sozu-libcargo test -p sozucargo test -p sozu-e2e -- --skip tests::fuzz_tests::--ignoredcells (ci.yml:182-184)check_doc_citations.py --root ./--base/--self-testgit merge-tree --write-tree origin/main <head>Note the two
sozu-simcells build a 0-test binary unlesstokio_unstableis set — run with
RUSTFLAGS='--cfg tokio_unstable'they are 6 and 6 passed.An earlier intermediate base produced three red e2e runs with disjoint
failure sets at 1-minute load 14–30 on 8 cores; all passed in isolation, and the
verbatim suite went 446/0 at load 9.6. Load-dependent, not a regression — and
the only candidate code explanation was ruled out directly (#1452's sole live
change replaced the literal
4096with a named constant of the same value).