Repository navigation
test(h2): cover the vectored write loop's progress-under-WouldBlock branch - #1472
Merged
Merged
Conversation
…ranch `update_readiness` (`mux/mod.rs`) classifies a write pass as stalled **iff `size == 0`** — `status` only clears the event bit. So a `socket_write_vectored` returning `size > 0` together with `SocketResult::WouldBlock` is NOT a stall, and `flush_stream_out`'s `while !kawa.out.is_empty()` loop must go round again. A write machine that treated `status != Continue` as a pass terminator would drop that second write and send the response short. Nothing exercised that branch against production code. `FrontRustls` is the only handler that returns the pair at all, and it does so structurally: `socket_write_vectored` accumulates `buffered_size` from `session.writer().write(..)` — plaintext rustls accepted — while `can_write` goes false when `write_tls` blocks against the kernel. The two quantities are independent. A plain `mio::net::TcpStream` answers `(0, WouldBlock)` and never that shape, and `BackpressuredTlsSocket::socket_write_vectored` delegated straight to one. `h2_transmit`'s `qc_partial_writes_preserve_the_byte_stream` does drive partial writes, but through `drive`, a loop written in its own test module that calls neither `flush_stream_out` nor `update_readiness_after_write` and whose `WritePlan` carries an accept count and no `SocketResult` at all — a mirror cannot constrain what it mirrors, and that plan cannot express the pair. Extends `BackpressuredTlsSocket` with an optional `(size, status)` script for `socket_write_vectored` rather than adding a second fault-injecting handler: the pair is a TLS artefact, so it belongs on the handler that already models rustls, one layer below the record count it already models. An empty script — the default — delegates as before, so the three tests that predate it are unaffected. Scripted sizes are clamped to the gather's offer so no production `debug_assert!` can stand in for a test assertion. Adds five tests: - `a_partial_write_reporting_would_block_continues_the_pass` — the branch above, driven through the production `flush_stream_out`. Against the pass-terminator mutation it is the ONLY failure in the 1083-test `sozu-lib` suite, on its own assertion (`left: 5, right: 43`). - `a_fully_accepted_write_drains_in_one_round` and `a_write_that_moves_no_bytes_stalls_the_pass` — the two arms that were already covered, kept as standing controls. Both pass against the correct loop and against that mutation, which is what shows the suite's existing shape proves nothing about this vector. - `force_disconnect_re_arms_while_tls_records_are_pending` and `force_disconnect_closes_when_no_tls_records_are_pending` — the site #1454 names. `h2_close::force_disconnect_action` is exhaustively tabled over its two booleans, but nothing called `ConnectionH2::force_disconnect`, so the query that feeds the table and the wiring of `ReArmAndContinue` to interest, flush and return value had no coverage. Hard-wiring `false` at the query site reddens exactly one test, the first of these two. Hard-wiring `true` reddens two: the second of these and the pre-existing `a_flush_that_succeeds_closes_within_one_writable_call`, which reaches the same call through `writable()`'s GoAway fall-through. So the pair's value against `true` is the direct path to `ConnectionH2::force_disconnect`, not the catch itself; against `false` it is the catch. Test-only; no production line changes. `sozu-lib` goes from 1078 to 1083. Refs #1454 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 15:15
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 23, 2026
`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
added a commit
that referenced
this pull request
Sep 23, 2026
`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]>
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.
Closes the test gap #1454 names, ahead of the
write_streamsinversion that gap exists to constrain.The branch in one paragraph
update_readiness(lib/src/protocol/mux/mod.rs:380-404) classifies a write pass as stalled iffsize == 0. Thestatusargument only clears the event bit. Sosocket_write_vectoredreturningsize > 0together withSocketResult::WouldBlockis not a stall, andflush_stream_out'swhile !kawa.out.is_empty()loop must go round again. The natural reading of the code — "a non-Continuestatus means stop" — is the wrong one, and a write machine built on it sends responses short. Nothing in the suite exercised that branch. Now five tests do.Test-only. Zero production lines change: the
#[cfg(test)] mod testsboundary opens at line 6332 onmainand every hunk here lands at 7291+.sozu-libgoes 1078 → 1083.Why extend
BackpressuredTlsSocketrather than add a second handler(size > 0, WouldBlock)is a TLS artefact —FrontRustlsis the only handler that produces it, and it does so structurally:socket_write_vectoredaccumulatesbuffered_sizefrom plaintext rustls accepted intosession.writer(), whilecan_writegoes false whenwrite_tlsblocks against the kernel (lib/src/socket.rs:934-1134). The two quantities are independent. A plainmio::net::TcpStreamanswers(0, WouldBlock)and can never produce the pair.So the script belongs on the handler that already models rustls, one layer below the record count it already models. An empty script — the default — delegates exactly as before, which is why the three tests that predate it are untouched and unaffected. Scripted sizes are clamped to the gather's offer, so no production
debug_assert!can stand in for a test assertion.h2_transmit'sqc_partial_writes_preserve_the_byte_streamlooks like prior coverage and is not: it drives partial writes throughdrive, a loop in its own test module that calls neitherflush_stream_outnorupdate_readiness_after_write, over aWritePlancarrying an accept count and noSocketResultat all. A mirror cannot constrain what it mirrors, and that plan cannot express the pair.Each test names the production edit that reddens it
statusath2.rs:2752a_partial_write_reporting_would_block_continues_the_pass,left: 5, right: 43update_readiness'selsearm →falsea_write_that_moves_no_bytes_stalls_the_pass,got Drainedfalsefortls_wants_writeath2.rs:5842force_disconnect_re_arms_while_tls_records_are_pending,got CloseSessiontruefortls_wants_writeath2.rs:5842force_disconnect_closes_when_no_tls_records_are_pendingand the pre-existinga_flush_that_succeeds_closes_within_one_writable_callself.readiness.interest = …ath2.rs:5854force_disconnect_re_arms…,left: Hup, right: Writable | Error | Hupself.ensure_tls_flushed();ath2.rs:5855force_disconnect_re_arms…, event bitbytes_writtenaccumulation ath2.rs:2746a_fully_accepted_write…left: 0, right: 43+a_partial_write…Every failure above is a test's own
assert!; no productiondebug_assert!ever pre-empted one.The
truerow is why the twoforce_disconnecttests are not a symmetric pair.h2_close::force_disconnect_actionis exhaustively tabled over its two booleans, but nothing calledConnectionH2::force_disconnect, so the query feeding the table and the wiring ofReArmAndContinueto interest, flush and return value had no coverage. Againstfalsethe new test is the catch. Againsttrueit is not — the pre-existing test already catches that, throughwritable()'s GoAway fall-through — and the new test's value is the direct path toConnectionH2::force_disconnect, where a red names the query under test instead of arriving through a write pass and a state machine.What this branch does not buy — stated so the inversion is reviewed against it
flush_stream_outhas one producer ofFlushOutcome::Stalled(h2.rs:2753) and exactly two consumers:h2.rs:2266, the resume path'sreturn MuxResult::Continue, andh2.rs:2597, the main loop'sset_expect_write(Some(..)); break 'outer. Both are reached by zero tests, before and after this branch. Apanic!planted ath2.rs:2753gives1082 passed; 1 failed, the sole reacher beinga_write_that_moves_no_bytes_stalls_the_pass— which calls the associated function directly. No test entersflush_stream_outwithdebug_site = 2at all.These five tests pin the inside of the flush loop. The
write_streamsinversion lifts the round-again decision out of it, so the riskiest edits it makes are in code no test observes. Three shapes that would survive this suite:flush_stream_outkeeps its signature but stops being the loop — all five tests stay green against a vestigial function.statusrather thanoutcomeath2.rs:2597's neighbourhood. Combined withh2_close::finalize_actionsuppressing the finalize flush oncesocket_wants_write()is true (h2.rs:2897-2900), the pass can end withReady::WRITABLEwithdrawn and no external trigger — a hang, not a truncation.total_bytes_writtenmis-accumulation ath2.rs:2595, which feedsfinalize_write'sbytes_written_this_passand selects invariant-16RetainPendingBackoverQuiesce.The new
response_stream_with_out_blockshelper builds a stream carrying response bytes; installing it in aContextand driving it throughwritable()is the step that makes sites 2266 and 2597 reachable. It is deliberately not in this branch — different fixture, different failure mode, and holding this one open for it delays the work it exists to constrain. Recorded on #1454 so the inversion is reviewed against a known blind spot rather than an assumed-covered one.Refs #1454