Skip to content

test(h2): reach the two unreached write-path stall sites and pin the pass-progress fold - #1475

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
test/h2-write-path-reachability
Sep 23, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
test/h2-write-path-reachability

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

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_streams inversion is most likely to break. Test-only: the production region is byte-identical to main (md5sum of h2.rs lines 1–6331, up to the #[cfg(test)] at 6332 — d14838f4f1f0d20b3f40336d3f5a2ca4 on both).

The sites, and the probe that proves they were unreached

flush_stream_out has one producer of FlushOutcome::Stalled and two consumers:

site what it does
h2.rs:2266 the resume path's return MuxResult::Continue
h2.rs:2597 the main loop's set_expect_write(Some(..)); break 'outer

A panic! planted at both sites before this change leaves the suite entirely green. A panic! on the resume block's first line shows debug_site = 2 had 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_pass at 2266 and a_stalled_stream_parks_expect_write_for_the_next_pass at 2597.

Every test names the production edit that reddens it

edit failing test left / right
terminate the pass on !matches!(status, Continue) a_partial_write_reporting_would_block_continues_the_pass_through_writable 5 / 43
delete set_expect_write in the stall branch a_stalled_stream_parks_expect_write_for_the_next_pass None / Some(Other { id: 1, gid: 0 })
delete the resume path's return MuxResult::Continue a_stalled_resume_does_not_begin_a_scheduler_pass None / Some(Other { id: 1, gid: 0 })
seed total_bytes_written from resume_bytes resume_path_bytes_do_not_make_the_pass_progress Writable|Error|Hup / Error|Hup
order.iter().chain(order.iter()) a_yielded_incremental_stream_is_prepared_once_per_pass 65535 / 32768
total_bytes_written = stream_bytes a_later_zero_byte_stream_does_not_erase_the_pass_progress Error|Hup / Writable|Error|Hup

Every 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: a write_streams-local edit that never touches flush_stream_out reddens the new test while the twin stays green.

The one that matters most

a_later_zero_byte_stream_does_not_erase_the_pass_progress closes a gap the rest of the suite could not see. Mutating h2.rs:2596 from

total_bytes_written = total_bytes_written.saturating_add(stream_bytes);

to 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_written becomes 0 instead of 73. finalize_write then passes bytes_written_this_pass > 0 as false into h2_close::finalize_action; expect_write_parked is false, so RetainPendingBack is skipped and the pass falls through to Quiesce, stripping Ready::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_write is 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.prepare on 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:

production  : delta=64 vectored_calls=2 blocks_left=1 bout=73 s_events=1 io_events=2
double-visit: delta=64 vectored_calls=2 blocks_left=1 bout=73 s_events=2 io_events=2

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, so incr!(names::h2::FLOW_CONTROL_STALL) fires on the second visit (and incr!(names::backend::FLOW_CONTROL_PAUSED) on Position::Client). Proven by planting a panic! on that incr!: the fixture does not reach it under production and does under the double visit. And context.debug.push(DebugEvent::S(..)) sits outside the prepare gate's closing brace, firing once per visit — s_events 1 → 2 while io_events stays 2 — so each extra entry evicts a real one from the bounded DebugHistory ring.

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: consumed debits both *parts.window and flow_control; note_fired has its own consumed > 0 gate; rst_sent is load-bearing because H2BlockConverter::initialize pushes a RST_STREAM on every prepare of an errored kawa with no window gate at all; and headers_response is mem::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_action tests expect_write_parked before made_progress, so a stalled stream's bytes can never reach the progress decision. No test was added for it.

Rounds inside flush_stream_out remain invisible to write_streams — the loop returns only Drained or Stalled — so no round-keyed edit is expressible at that level, and a_yielded_incremental_stream_is_prepared_once_per_pass pins prepare-once-per-stream-per-pass rather than partial-write keying.

No absolute suite counts

Ten embedded NNNN passed totals 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.py covers only doc/ and **/LIFECYCLE.md, so any test added anywhere in sozu-lib silently falsified them. The reddening recipes and left:/right: values are kept, since those are durable.

sozu-lib goes 1088 → 1089.

Refs #1454

`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
FlorentinDUBOIS merged commit 19fd5d8 into main Sep 23, 2026
42 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant