Repository navigation
test(h2): reach the two unreached write-path stall sites and pin the pass-progress fold - #1475
Merged
Merged
Conversation
`flush_stream_out` has one producer of `FlushOutcome::Stalled` and exactly
two consumers — the resume path's `return MuxResult::Continue`, and the main
loop's `set_expect_write(Some(H2StreamId::Other { .. })); break 'outer;` —
and no test reached either. Measured on 38fe585 (whose tree 1e414ed
squash-merged unchanged) with a `panic!` planted at BOTH consumers at once:
`1083 passed; 0 failed`. A `panic!` on the `return FlushOutcome::Stalled`
they both read gives `1082 passed; 1 failed`, the sole reacher being
`a_write_that_moves_no_bytes_stalls_the_pass`, which calls the associated
function directly and never enters `write_streams`. A `panic!` on the first
line of the resume block also leaves `1083 passed; 0 failed`: nothing called
`flush_stream_out` with `debug_site = 2`.
The gap was never the socket — `with_vectored_script` already scripts any
`(size, status)` pair, including ones no kernel returns. It was registering a
stream that carries response bytes, so the scheduler reaches it through
`writable()`. Production is untouched: every hunk lands inside `#[cfg(test)]
mod tests`, and `md5sum` over h2.rs lines 1..6331 — up to the `#[cfg(test)]`
boundary — is d14838f4f1f0d20b3f40336d3f5a2ca4 on this commit and on
1e414ed alike.
Six tests, each with a measured reddening edit. Counts below are against this
commit's 1089.
- `a_partial_write_reporting_would_block_continues_the_pass_through_writable`
pins that a write which moved bytes under `WouldBlock` does not end the
pass, driven through `writable()` rather than by calling the associated
function. Adding `|| !matches!(status, SocketResult::Continue)` to
`flush_stream_out`'s stall test gives `1086 passed; 3 failed`, this test
failing on its own first assertion with `left: 5, right: 43`.
- `a_stalled_stream_parks_expect_write_for_the_next_pass` reaches the main
loop's stall consumer. Deleting its `set_expect_write` gives `1088 passed;
1 failed`, with `left: None, right: Some(Other { id: 1, gid: 0 })`.
- `a_stalled_resume_does_not_begin_a_scheduler_pass` reaches the resume
path's stall consumer. Deleting its `return MuxResult::Continue` gives
`1088 passed; 1 failed`, with `left: None, right: Some(Other { id: 1, gid:
0 })`.
- `resume_path_bytes_do_not_make_the_pass_progress` pins that resume-path
bytes are not pass progress, so `finalize_write` quiesces instead of
retaining WRITABLE under LIFECYCLE §9 invariant 16. Hoisting `resume_bytes`
out of the resume block and seeding `total_bytes_written` from it gives
`1088 passed; 1 failed`, with `left: Writable | Error | Hup, right: Error |
Hup`.
- `a_yielded_incremental_stream_is_prepared_once_per_pass` pins that one pass
debits the connection send window once per stream, even when that stream's
flush goes round twice. Visiting each stream twice within a pass
(`order.iter().chain(order.iter())`) gives `1088 passed; 1 failed`, with
`left: 65535, right: 32768`.
- `a_later_zero_byte_stream_does_not_erase_the_pass_progress` pins the
pass-level accumulation `total_bytes_written =
total_bytes_written.saturating_add(stream_bytes)`, which nothing covered.
Replacing it with `total_bytes_written = stream_bytes;` leaves the whole
suite green WITHOUT this test — measured `1088 passed; 0 failed`, the other
five included — and gives `1088 passed; 1 failed` with it, on its own first
assertion, `left: Error | Hup, right: Writable | Error | Hup`. The failure
it hides is a hung response: stream 1 delivers a frame and keeps blocks
queued, stream 3 is window-blocked and writes nothing, the total reads 0,
`finalize_action` skips `RetainPendingBack` and falls through to `Quiesce`,
`Ready::WRITABLE` is stripped, and edge-triggered epoll never re-fires.
The send-window test's shape is measured rather than assumed, and the
measurement corrects the obvious way to write it. A narrow per-stream window
cannot see a double prepare: with a 64-byte window over a 200-byte body and a
two-round flush, production and a literal double-visit edit both give
`delta=64 vectored_calls=2 blocks_left=1 bout=73`. `*parts.window =
parts.window.saturating_sub(consumed)` zeroes the stream's credit, the second
prepare computes `min(0, connection_window) == 0`, the converter's `window >
0` gate returns the chunk untouched, and `consumed = 0 - 0 = 0`.
That makes the second prepare invisible to those observables, NOT harmless.
Two things do move, measured on the same fixture: the converter's
flow-control-stall arm fires its unconditional
`incr!(names::h2::FLOW_CONTROL_STALL)` — proven with a `panic!` on that
`incr!`, which the fixture does not reach under production and does reach
under the double visit — and would also fire
`incr!(names::backend::FLOW_CONTROL_PAUSED)` on `Position::Client`; and
`context.debug.push(DebugEvent::S(..))`, which sits outside the prepare
gate and so fires per visit, measured 1 -> 2 while the SocketIO count stays
2. Those counters are dashboard signals for a real RFC 9113 §6.9 condition,
so a re-entrant write loop would inflate them with stalls that never reached
the wire. The bytes are idempotent; the telemetry is not.
The bytes are idempotent by four independent mechanisms, only one of which is
the window, and the comment now says so: the `consumed` double debit;
`H2Scheduler::note_fired`'s own `consumed > 0` gate; the `rst_sent` HashSet,
which is load-bearing because `H2BlockConverter::initialize` pushes a
RST_STREAM on every prepare of an errored kawa with no window gate at all;
and `mem::take` of the response-header edits.
The RFC 9218 §4 incremental yield is the one path that stops a prepare with
BOTH window and blocks remaining, which is why that test registers a
same-urgency incremental pair over a body wider than
`SETTINGS_MAX_FRAME_SIZE`. Its name says what it pins: a round-again-keyed
edit is not expressible in `write_streams`, because `flush_stream_out` drains
`kawa.out` completely or stalls and the rounds are invisible above it.
What the existing fixture cannot see:
`a_partial_write_reporting_would_block_continues_the_pass` drives the same
two-round flush but calls `flush_stream_out` directly — no `Context`, no
scheduler, no converter, no `H2FlowControl` — so it never runs a prepare at
all, and no amount of re-preparing is representable in it.
No absolute suite count is embedded in the new comments, and the parent
commit's two were rewritten the same way: a whole-crate pass count is
falsified by a test added anywhere in `sozu-lib`, and nothing checks it —
`check_doc_citations.py` reads only `doc/` and `**/LIFECYCLE.md`. The failing
test names and the `left:`/`right:` values survive; the totals did not. Both
of the parent's relative claims were re-verified and still hold: forcing
`force_disconnect_action`'s second argument to `true` fails
`force_disconnect_closes_when_no_tls_records_are_pending` and
`a_flush_that_succeeds_closes_within_one_writable_call`; forcing it to
`false` fails only `force_disconnect_re_arms_while_tls_records_are_pending`.
The suite goes from 1083 to 1089 tests.
Refs #1454
Refs #1472
Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 16:39
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.
Two production sites in the H2 write path had zero test coverage. This adds six tests that reach them and pins five adjacent properties the
write_streamsinversion is most likely to break. Test-only: the production region is byte-identical tomain(md5sumofh2.rslines 1–6331, up to the#[cfg(test)]at 6332 —d14838f4f1f0d20b3f40336d3f5a2ca4on both).The sites, and the probe that proves they were unreached
flush_stream_outhas one producer ofFlushOutcome::Stalledand two consumers:h2.rs:2266return MuxResult::Continueh2.rs:2597set_expect_write(Some(..)); break 'outerA
panic!planted at both sites before this change leaves the suite entirely green. Apanic!on the resume block's first line showsdebug_site = 2had no caller at all. After this change the same both-sites probe fails exactly twice, one test per site —a_stalled_resume_does_not_begin_a_scheduler_passat 2266 anda_stalled_stream_parks_expect_write_for_the_next_passat 2597.Every test names the production edit that reddens it
!matches!(status, Continue)a_partial_write_reporting_would_block_continues_the_pass_through_writable5/43set_expect_writein the stall brancha_stalled_stream_parks_expect_write_for_the_next_passNone/Some(Other { id: 1, gid: 0 })return MuxResult::Continuea_stalled_resume_does_not_begin_a_scheduler_passNone/Some(Other { id: 1, gid: 0 })total_bytes_writtenfromresume_bytesresume_path_bytes_do_not_make_the_pass_progressWritable|Error|Hup/Error|Huporder.iter().chain(order.iter())a_yielded_incremental_stream_is_prepared_once_per_pass65535/32768total_bytes_written = stream_bytesa_later_zero_byte_stream_does_not_erase_the_pass_progressError|Hup/Writable|Error|HupEvery failure lands on the test's own first assertion; no production
debug_assert!stands in for one. Four of the six fail alone. The first fails alongside its direct-call twin and the incremental test — three independent witnesses of one bug, landing on three different observables (bytes_written,metrics.bout, the connection window debit) from three different fixtures, which is layering rather than coupling. That it is not a duplicate of the twin is itself proven: awrite_streams-local edit that never touchesflush_stream_outreddens the new test while the twin stays green.The one that matters most
a_later_zero_byte_stream_does_not_erase_the_pass_progresscloses a gap the rest of the suite could not see. Mutatingh2.rs:2596fromto
total_bytes_written = stream_bytes;left the entire suite green — 1088 passed, the other five new tests included.The failure it hides is a hung response, not a cosmetic one. Two streams in one pass: stream A yields cleanly under RFC 9218 §4 after one window-capped DATA frame, keeping blocks and setting no
expect_write; stream B is eligible but writes nothing on a zero send window.total_bytes_writtenbecomes 0 instead of 73.finalize_writethen passesbytes_written_this_pass > 0as false intoh2_close::finalize_action;expect_write_parkedis false, soRetainPendingBackis skipped and the pass falls through toQuiesce, strippingReady::WRITABLE. Edge-triggered epoll never re-fires and stream A's remaining body is stranded — LIFECYCLE §9 invariant 16 violated.This is also the defect a uniform
handle_writeis most likely to reintroduce, since folding the resume and main paths into one counter is the natural implementation.A correction carried in the comments
An earlier draft of this branch claimed a second
kawa.prepareon the same stream is "a genuine no-op — no observable moves". That is wrong, and the comments now say so. Measured on one fixture with five observables:The bytes are idempotent; the telemetry is not.
converter.rs's flow-control-stall arm is reached because the window is zero and is not itself window-gated, soincr!(names::h2::FLOW_CONTROL_STALL)fires on the second visit (andincr!(names::backend::FLOW_CONTROL_PAUSED)onPosition::Client). Proven by planting apanic!on thatincr!: the fixture does not reach it under production and does under the double visit. Andcontext.debug.push(DebugEvent::S(..))sits outside the prepare gate's closing brace, firing once per visit —s_events1 → 2 whileio_eventsstays 2 — so each extra entry evicts a real one from the boundedDebugHistoryring.Both counters are dashboard signals for a real RFC 9113 §6.9 condition, so a re-entrant write loop would read backpressure into a connection that had none.
The comments record why the bytes are safe, because only one of the four mechanisms is the window:
consumeddebits both*parts.windowandflow_control;note_firedhas its ownconsumed > 0gate;rst_sentis load-bearing becauseH2BlockConverter::initializepushes a RST_STREAM on every prepare of an errored kawa with no window gate at all; andheaders_responseismem::taken. A reader who keeps only "harmless" would drop the wrong guard.Not asserted, deliberately
Dropping a stalled stream's partial bytes from the pass total is also suite-green, but it is inert by construction:
finalize_actiontestsexpect_write_parkedbeforemade_progress, so a stalled stream's bytes can never reach the progress decision. No test was added for it.Rounds inside
flush_stream_outremain invisible towrite_streams— the loop returns onlyDrainedorStalled— so no round-keyed edit is expressible at that level, anda_yielded_incremental_stream_is_prepared_once_per_passpins prepare-once-per-stream-per-pass rather than partial-write keying.No absolute suite counts
Ten embedded
NNNN passedtotals across this file (eight new, two from the parent) have been replaced with relative claims — "the only failure in the suite". Nothing checks such numbers:.github/scripts/check_doc_citations.pycovers onlydoc/and**/LIFECYCLE.md, so any test added anywhere insozu-libsilently falsified them. The reddening recipes andleft:/right:values are kept, since those are durable.sozu-libgoes 1088 → 1089.Refs #1454