Repository navigation
refactor(mux-h2): move the HPACK coders and scratch buffers into hpack_state - #1403
Merged
Merged
Conversation
…k_state Pure move, no behaviour change. Relocates the six HPACK-owned fields that lived directly on ConnectionH2 — the loona_hpack Decoder/Encoder pair and the four scratch Vecs (converter_buf, lowercase_buf, cookie_buf, priorities_buf) — into a new lib/src/protocol/mux/hpack_state.rs module. ConnectionH2 keeps a single `hpack: HpackState` field, so ownership does not split, but HpackState's fields are private to that module: every access now goes through an accessor (decoder_mut, encoder_mut, set_decoder_max_allowed_table_size, set_encoder_max_table_size, take/put_converter_buf, take/put_lowercase_buf, take/put_cookie_buf, take/put_priorities_buf, shrink_converter_buffers, reclaim_idle_buffers), so nothing outside hpack_state.rs can reach the raw HPACK state anymore. That compiler-enforced narrowing is the point of this step: it is the first cut of the strangler extraction turning ConnectionH2 into a sans-io core. Construction still happens exactly once, in ConnectionH2::new, with the same set_max_allowed_table_size call on the decoder. The two SETTINGS table-size-adjustment sites (ACK sync, SETTINGS_HEADER_TABLE_SIZE) now go through the new setters. write_streams still borrows the encoder for the whole write pass via encoder_mut(); priorities_buf now has to be taken out by value (take_priorities_buf) before that borrow starts and put back after, because collapsing the encoder and the scratch buffers into one struct field removes the automatic disjoint-field borrowing the compiler previously gave four separate ConnectionH2 fields — this was the one place the move was not purely mechanical. shrink_converter_buffers and the cancel_timed_out_streams reclaim block both move onto HpackState unchanged, just parameterised by the existing SCRATCH_BUF_RETAIN constant. converter.rs needed no change: H2BlockConverter already borrowed `&'a mut loona_hpack::Encoder<'static>`, which is exactly what encoder_mut() returns. Also updates the h2.rs/mod.rs line citations in LIFECYCLE.md that this diff shifted, including two that were already stale before this change (h2.rs:879 and the "mod tests onward" anchor) and are left pointing at the same content as before, not corrected, since fixing pre-existing drift is out of scope here. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 21, 2026 18:40
This was referenced Sep 21, 2026
refactor(mux-h2): extract the flood detector, and remove the module's last self-sampling clock
#1419
Merged
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.
First step of the H2 sans-io extraction decided on 2026-09-21 (#1339, #1336). It is deliberately the
smallest one, and it should be reviewed as "is this a pure move with zero behaviour change" — not
as a design review. The design is settled on the issues.
What moves
The six HPACK-owned values that lived directly on
ConnectionH2— theloona_hpackDecoder/Encoderpair and the four reusable scratch buffersconverter_buf,lowercase_buf,cookie_buf,priorities_buf— move into a newlib/src/protocol/mux/hpack_state.rs.ConnectionH2keeps a singlehpack: HpackStatefield, so ownership does not split: the struct stillowns the state for the same lifetime. What changes is that
HpackState's fields are private to thatmodule, so nothing outside it can reach the raw HPACK state. That compiler-enforced narrowing is the
whole point of this step — it is the mechanism by which later steps can move the state without hunting
for stray field accesses.
Construction still happens exactly once, in
ConnectionH2::new, with the sameset_max_allowed_table_sizecall. The two SETTINGS table-size-adjustment sites now go throughsetters.
converter.rsneeded no change at all:H2BlockConverter::encoderalready has exactly thetype
HpackState::encoder_mut()returns.Two things that are not purely mechanical, called out rather than absorbed
priorities_bufjoins the take/put pattern, and there is an early return between the two.Collapsing four separate fields into one struct removed the disjoint-field borrowing the compiler gave
for free, so
priorities_bufnow has to be taken out beforeencoder_mut()borrowsself.hpackforthe pass — the same pattern the other three scratch buffers already used.
write_streamshas an earlyreturn result;on theaccount_emitted_rstGOAWAY path between the take and the put, so on thatpath the buffer is not returned to
HpackState.This is not a state loss: the baseline does
priorities_buf.clear()then.extend(...)at the top ofevery write pass, so the buffer carries nothing across passes. The cost is one lost allocation
capacity on a rare error path, and it makes
priorities_bufbehave exactly likeconverter_buf,lowercase_bufandcookie_buf, which have had this shape all along.A
needless_range_loopclippy fired only after the buffer became a local.'outer: for idx in 0..priorities_buf.len()became'outer: for &stream_id in &priorities_buf.idxwas used solely toindex
priorities_buf, and the vector is not mutated inside the loop, so iteration order and valuesare unchanged. No
#[allow]was added.Documentation
LIFECYCLE.md's value is line-accurate citations, and this diff shiftsh2.rsby up to 20 lines andmod.rsby one. 95 citations were re-anchored.They were verified by content rather than by arithmetic: for each one, the text at the old line in the
base revision was compared against the text at the new line here. 94 are byte-identical.
The 95th is a correction of pre-existing drift, stated here so it is not laundered by the
renumbering around it. §5.1 describes
expect_read/expect_write; its citation readh2.rs:1731-1732, which at the base pointed atexpect_writeandlast_stream_id— off by one, fromsome earlier edit. It now reads
1733-1734and points at the pair the prose actually describes.Three further citations outside
LIFECYCLE.mdhad drifted and are fixed: two indoc/testing.md(
h2.rs:6142→6122,mod.rs:1306→1307) and onemod.rscitation insideLIFECYCLE.md(
mod.rs:2344→2345-2346, widened to cover the!is_draining()guard and thegraceful_goawaycallit guards, which is what the surrounding prose describes).
Two citations that were already stale before this changeset are deliberately left alone rather
than mixed into a pure move —
h2.rs:879in invariant 7 (rst_sent.contains, whose real site iselsewhere) and invariant 20's marker for the start of
#[cfg(test)] mod tests. Both want a follow-up.Validation
Run on the branch, exit codes checked directly rather than through a pipe.
Note for anyone re-running the tests:
cargo test -p sozu-libprints threetest result:lines andthe last two are empty filtered suites, so a
tailon that command showsrunning 0 testsand tellsyou nothing.
What this does not do
No behaviour change, no new dependency, no
async fn, no API surface outsidemux/. It does not yetintroduce
BufferSource, which is a decision on #1336 and not yet code. It does not touch thezero.storagedual-role problem — that is the reassembly step, several changesets away.Refs #1336, #1339.