Repository navigation
Description
ConnectionH2::flush_pending_control_frames has four stages that touch self.zero.storage. Three of
them are guarded. The first is not.
// stage 1 — no guard
if self.frontend_hung_up_while_draining() {
self.stream_table.set_expect_write(None);
self.zero.storage.clear();
...
}
// ... later stages, all guarded:
&& !self.header_block_reassembly_in_progress(); // WINDOW_UPDATE
&& !self.header_block_reassembly_in_progress() // deferred initial GOAWAY
&& !self.header_block_reassembly_in_progress() // RST_STREAMself.zero is both the HEADERS+CONTINUATION reassembly accumulator — header_block_fragment is a
(start, len) window into it that must survive multiple readable() passes until END_HEADERS — and
the control-frame write scratch. Clearing it mid-reassembly corrupts the accumulating field block
while the recorded length keeps growing, so the bytes still HPACK-decode and the failure mode is
silently wrong header values, not a crash.
This is the fourth instance of the same class
- fix(mux-h2): decode a refused stream's HPACK field block instead of dropping it #1396 (
42ac35bf) — a refused stream's field block dropped without decoding it into the
connection-level HPACK decoder, desyncing it from the peer's encoder. - fix(mux-h2): defer control-frame flush during header-block reassembly #1397 (
610eaa04) — an unrelated WINDOW_UPDATE/RST_STREAM flush clearingzero.storage
mid-reassembly. No adversarial peer required. - fix(mux-h2): defer graceful_goaway's GOAWAY during header-block reassembly #1401 (
e0e74097) — the same ingraceful_goaway, firing unconditionally on every drain landing
mid-reassembly.
Each of those added the guard to the stage it fixed. None of them looked at the stage above.
Reachability
frontend_hung_up_while_draining() requires only self.drain.draining() plus a HUP or ERROR readiness
event. Neither excludes a connection parked in H2State::ContinuationHeader or ContinuationFrame.
Two ordinary paths reach it:
- a peer signals TCP FIN together with a last, still-incomplete CONTINUATION frame in one
edge-triggered read; graceful_goawaysetsdrainingmid-reassembly — which is exactly what fix(mux-h2): defer graceful_goaway's GOAWAY during header-block reassembly #1401 established can
happen — and a HUP arrives immediately after.
Neither needs a hostile peer. The second is a normal operator-initiated drain racing an ordinary
client.
Suggested fix, and the reason to look wider than one line
Adding && !self.header_block_reassembly_in_progress() to stage 1 would match its three siblings. But
four instances of one class, each fixed in isolation, is the argument for something stronger than a
fifth guard.
The reassembly accumulator and the control-frame scratch are two roles with incompatible lifetimes
sharing one buffer. As long as they do, every future code path that reuses self.zero is one forgotten
guard away from silent header corruption, and the guard is invisible at the point where someone adds a
new stage.
The H2 sans-io extraction's reassembly step is the natural moment to separate them: a dedicated
accumulator with a real owned lifetime, and a caller-supplied scratch region for control-frame
serialisation. Then the collision is not guarded against — it is unrepresentable.
LIFECYCLE.md invariant 24 now names this hazard explicitly, with the three PRs above as provenance,
so at least a reviewer has something citable until that lands.
What I verified, and what I did not
Verified by reading flush_pending_control_frames in full: stage 1's self.zero.storage.clear() under
frontend_hung_up_while_draining() with no reassembly guard, and the && !self.header_block_reassembly_in_progress()
conjunct present on each of the three stages below it, in the same function.
Not verified: no runtime reproduction was attempted. Reaching it needs a peer that sends an
incomplete CONTINUATION and then hangs up during a drain; the reasoning above says that is sufficient,
but nobody has run it. A regression test in the shape of
a_legitimate_continuation_survives_a_graceful_goaway — which pins #1401 — would be the natural place
to prove it, and would be the red for whoever fixes this.
Activity
refactor(mux-h2): separate HEADERS+CONTINUATION reassembly from contr…
refactor(mux-h2): separate HEADERS+CONTINUATION reassembly from contr…
refactor(mux-h2): split zero.storage's dual role so a control-frame f…