Repository navigation
refactor(mux-h2): put the H2 core's buffers and HPACK state under a BufferSource - #1496
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 05:59
FlorentinDUBOIS
force-pushed
the
refactor/h2-buffer-source
branch
2 times, most recently
from
September 24, 2026 08:34
cc92b86 to
aa122ee
Compare
…ource Q1 of #1336 takes option (c) and Q14 answers yes, together: the core keeps a caller-implemented buffer source it may call mid-request and that may fail, and the HPACK state comes under that same contract rather than allocating on its own. Answering them apart would leave a core that borrows its wire buffers while allocating its header state, which bounds nothing. `BufferSource` has two calls: `checkout` for wire octets, and `scratch` for a reusable connection-lifetime buffer. `PoolBufferSource` is the one implementation, and each of its bodies is the expression that used to sit at the call site — an upgrade-then-checkout, and a plain `Vec::new()`. `Context` holds a `Box<dyn BufferSource>` where it held `pool`; `Stream::new`, `ConnectionH2::new`, `Connection::new_h2_server` / `new_h2_client` and `HpackState::new` take `&mut dyn BufferSource`. `HpackState::new` is fallible as a result: a refused scratch buffer refuses the connection on the path a refused stream-0 buffer already took. No behaviour changes. Every allocation happens where and when it did. What changes is who may be asked. The behaviour this had to preserve — exhaustion mid-request produces RST_STREAM(REFUSED_STREAM), never a connection error — had no coverage. It does now, added before the ownership moved: the simulator sizes its pool to three buffers so the connection's own takes one, the first stream takes the pair, and the second finds nothing, then requires exactly one refusal on the stream that could not be served, no GOAWAY, and the admitted stream still drivable to completion. Replacing the refusal with goaway(InternalError) reddens it. Left for its own changeset, deliberately: `loona_hpack` has no capacity-supplied constructor, so its tables are under the contract at acquisition and bounded by the RFC 7541 table-size settings, not routed through the source; growth of an already-granted scratch buffer still reaches the global allocator; `H2Scheduler`'s pass-order buffer holds stream ids rather than octets and is already bounded by the concurrent-stream admission gate; and `h2_header_reassembly`'s accumulator still has no bound. Refs #1336 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
refactor/h2-buffer-source
branch
from
September 24, 2026 09:40
aa122ee to
d41b54a
Compare
This was referenced Sep 24, 2026
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.
Refs #1336. First slice of the decided answer to Q1 and Q14.
Q1 took option (c) — a caller-implemented
BufferSourcethe core may call mid-request and that may fail — and Q14 answered yes, the HPACK state comes under the same contract. The pairing is the point: answering them apart gives a core that borrows its stream buffers while allocating its header state, which bounds nothing for a simulator.BufferSourcehad zero occurrences repo-wide. The decision was recorded 2026-09-21 and never implemented; its own comment deferred it until after thewrite_streamsinversion, which landed in #1479.The shape
PoolBufferSource::checkoutis literally the expression that sat at both call sites;scratchis literally whatHpackState::newdid. Zero behaviour change by construction — what changes is who may be asked.Two methods, not more. A
ScratchRole/put_scratchpair was sketched and dropped: the scratch buffers are owned byHpackStatefor the connection's lifetime and leased internally byH2ConverterPass::new/into_buffers, so a return path to the source would be a concept nothing calls.Context.poolbecomesContext.buffers: Box<dyn BufferSource>.HpackState::newbecomes fallible as a consequence, so a refused scratch refuses the connection on the path a refused stream-0 buffer already took.https.rsandrouter.rsboth pass&mut *context.buffers, so a session's connection and its streams draw from one source — no two ownership models coexist.The acceptance criterion had no test, which is the finding
(c) was chosen because it is the only option preserving today's observable behaviour: pool exhaustion mid-request produces
REFUSED_STREAM, not a connection error.Nothing in
lib/,e2e/orsim/covered that. Every existingREFUSED_STREAMtest coversMAX_CONCURRENT_STREAMS;connection.rs'sFORCE_NEW_H2_CLIENT_FAILUREis the backend construction path. The behaviour the decision rests on was unverified.So the test was added before ownership moved:
h2_pool_exhaustion_mid_request_refuses_the_stream_not_the_connection, with pool max 3 andmax_concurrent_streams64 so the pool and not the ceiling refuses. It asserts exactly oneRST_STREAM(REFUSED_STREAM)on stream 3, no GOAWAY, stream 1 still live and still drivable to completion. The oracle is decoded wire frames only — it never reads the "buffer pool exhausted" log.That also answers the simulator question posed in the brief: forcing exhaustion deterministically is already cheap today via pool sizing, no allocator injection needed.
Two corrections to the issue
Vecs" are three. TheHpackStateextraction already landed, andpriorities_bufleft with the scheduler extraction — it is nowH2Scheduler::order.BufferSourcegenuinely did not exist; the mechanism had shipped twice under other names (H2ConverterPass::new/into_buffers,drain_window_updates_into).Red-then-green, per test
h2_pool_exhaustion_…refuse_stream_and_discard(RefusedStream)→goaway(InternalError)saw 0 RST_STREAM frames in total / left: 0 right: 1, with>>> GOAWAY: InternalErrorin the loga_source_that_refuses_scratch_refuses_the_connectionHpackState::newuses.unwrap_or_default()instead of?a_pool_source_refuses_once_its_pool_is_exhaustedcheckoutunwraps the happy pathpoolexpect…_once_its_pool_is_gonebufferexpectAfter each,
h2.rswas restored and compared by md5 againstgit show origin/main:…— identical, and nogit stashused. Shared-literal check between production and test sides: empty.Boundary left, explicitly
This is the first piece, not half of everything. Named in the commit body, the CHANGELOG and the module doc:
loona_hpack's own tables — nowith_capacityexists, so they are under the contract at acquisition and bounded where they already were, by the RFC 7541 §4.2 table-size settings. Growth still reaches the global allocator.H2Scheduler::order— holdsStreamIds, not octets, so aVec<u8>method cannot serve it, and it is already bounded by the admission gate. Routing it would add a second element type for no bound gained.h2_header_reassembly's accumulator — still unbounded, tracked separately.Context::newstill takesWeak<RefCell<Pool>>and boxes it. That is the one placePoolenters; the core beneath never names it. A constructor taking a caller's ownBox<dyn BufferSource>is the follow-on that lets the simulator inject a refusing source.Verification
The
sozu-libbaseline was measured on a detachedorigin/mainworktree (1106), not derived.The 54 exempt spans were audited rather than accepted: for each, current content at the new line against base content at the old line —
54 spans point at byte-identical content; 0 mismatched; 0 point at lines with no base counterpart. Pure renumber from adifflibmap built only fromequalopcodes; 44 citations plus 2 pinned blocks were drifted by the line shifts and all were repaired.Rustdoc initially failed with exit 101 on four errors — two private-item intra-doc links in the new module and two
[Pool]links orphaned by removing the now-unused import. Fixed properly (plain code spans,crate::pool::Pool), not with an#[allow].No check weakened, no test deleted or ignored, no lint escape, no production dependency added, no
async fninlib/.