Repository navigation
refactor(mux-h2): reach TLS through three named seams instead of 21 raw socket calls - #1499
Merged
Merged
Conversation
`ConnectionH2` asked the TLS layer twenty-one questions and actions spelled
out as raw socket calls: sixteen `socket_wants_write()`, four empty-buffer
`socket_write(&[])` flushes and one `socket_close()`. They now go through
three private methods — `tls_wants_write`, `flush_tls_records` and
`begin_tls_close` — and `self.socket` in `h2.rs` production code drops from
26 occurrences to 8: the three seam bodies, the single `socket_read` of the
read path, the single `socket_write_vectored` of the stream-write path,
`flush_zero_to_socket`'s real write, and the two `socket_ref()` reaches that
the `Debug` impl and the RTT snapshot still own.
No behaviour change. The three bodies are delegations, every answer is
bit-identical, and `sozu-lib` is unmoved at 1107 tests.
The name of the trait method says socket, which is what made this read as an
I/O question for as long as it was written out at every site. It is a question
about a buffer that happens to live behind the socket: `FrontRustls` is the
only production `SocketHandler` that overrides it, the trait default is
`false`, and `Router::backends` is declared `Connection<SessionTcpStream>`
whatever the frontend is — so every backend H2 connection already answers
`false` at all fifteen call sites, statically. The seams are the three inputs
and actions the I/O shell will own; their bodies move there, their call sites
do not.
One local change that is not a substitution: `force_disconnect` reads the
answer once above its `match` rather than inside the `Position::Server` arm.
A method taking `&self` cannot coexist with the `&mut self.position` the
client arm holds for its `status` binding, and the server arm's own comment
already required a single read — the hoist extends that to both arms and to
every `wants_write=` a debug line renders.
Coverage of the new seams was measured rather than assumed, by replacing each
body with a constant and counting `cargo test -p sozu-lib --lib`:
tls_wants_write() -> false 1097 passed; 10 failed
flush_tls_records() -> (0, Continue), no flush 1103 passed; 4 failed
begin_tls_close() -> {} 1107 passed; 0 failed
The third is green, and `sozu-e2e` is green under it too at 447 passed — so
nothing in the tree detects it, not only nothing in the unit suite. It is a
pre-existing gap this changeset records rather than creates:
`initiate_close_notify` is reached only from `Mux::shutting_down` and neither
layer drives that path. #1484 independently listed that site among the ones it
could not reach, for the same reason. Closing it needs a driven close_notify
and belongs to its own changeset with its own test.
`h2_close`'s module doc and `doc/h2_mux_internals.md` name the seams where
they described the raw calls, and the latter gains a table of the three.
`LIFECYCLE.md`, `doc/testing.md` and eight pinned blocks in
`doc/h2_mux_internals.md` are re-anchored for the line shift; the drifted-
citation gate exempts 63 re-anchored spans from its comparison, and all 63
were audited against the base blob as byte-identical.
Refs #1339
Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 07:06
This was referenced Sep 24, 2026
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 24, 2026
…es at their flush points `ConnectionH2::finalize_write` and `ConnectionH2::flush_pending_control_frames` were the last two core functions that read `ConnectionH2::tls_wants_write`, acted on the answer, and read it again. Both now answer a step and let the shell that owns the socket perform it, on the `poll_read_target` / `handle_read` protocol this module already uses for the read half. Issue #1339, Q10. `finalize_write` gains a leading `tls_wants_write: bool` and returns `H2FinalizeTarget`: `Done(MuxResult)` for the RFC 9113 6.8 graceful GOAWAY and the four readiness answers of LIFECYCLE 9 invariant 16, `Flush` / `SkipFlush` for the two that need the TLS step. `write_streams` -- already the only site that touches the socket on the stream-write path -- reads the query, performs `flush_tls_records` for `Flush` and not for `SkipFlush`, reads it again, and hands that second answer to the new `finalize_write_after_flush`. The two stay two variants rather than one boolean because `h2_close::finalize_action` already distinguishes them, and the post-flush read stays a second call rather than a reused binding because it asks a different question: not "does rustls hold records" but "did the step between them land" -- `socket_write(&[])`'s `(size, status)` is discarded, so nothing else on this path can tell. `flush_pending_control_frames` answers `H2ControlFlushTarget` instead of `Option<MuxResult>`. `Proceed` is the former `None`, `Done(MuxResult)` the former `Some`, and `Stalled` is new: the zero-buffer resume, the WINDOW_UPDATE drain and the RST_STREAM drain used to read `tls_wants_write` and call `ensure_tls_flushed` themselves, and now return `Stalled` for `writable` to do it once for all three. That query could not become an input -- it has to be read after the `flush_zero_to_socket` whose stall produced it, because that write is what changes the answer. `ensure_tls_flushed`'s production call sites fall from eight to six. `flush_zero_to_socket` stays inside the function: it is a byte mover on the control-frame path, not a TLS seam. Behaviour-preserving. `cargo test -p sozu-lib` reads `1115 passed; 0 failed` at 84d979f and `1115 passed; 0 failed` here; nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: `write_streams` reads `tls_wants_write` before `finalize_write` runs the graceful-GOAWAY check that used to precede the query, so on that path the query now happens and its value is discarded. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, and counts flushes only. The count of `self.socket` reaches above `mod tests` is unchanged at eleven, which is the honest measure of this step: neither function ever held one, both reached the socket only through the three named seams of #1499. Six `TO SEE THIS RED` recipes repaired, each applied as written and the failure recorded. Four named `self.socket.socket_wants_write()` at sites #1499 and touched anything: the WINDOW_UPDATE-drain and RST_STREAM-drain stages, and the `error_close_action` and `goaway_close_action` call sites in `writable`. A fifth named `self.socket.socket_write(&[])` in the GoAway arm's `CloseAction::Flush` body, which is `self.flush_tls_records()`. The sixth, on `a_finalized_write_pass_flushes_once_and_re_arms_while_records_survive`, this changeset itself made wrong. Measured: the two drain recipes and both halves of the finalize recipe give `1114 passed; 1 failed` naming only their own test, `error_close_action(false)` gives `1114 passed; 1 failed` (the stale text said `1097`), and the `goaway_close_action` post-flush constant and the deferred-GOAWAY-flush recipe each give `1113 passed; 2 failed` (the stale text said `1096`), the second failure being `a_flush_that_does_not_drain_keeps_the_connection_open`. The three `log_context!` recipes that name `self.socket` deliberately were read and left alone: they ask a reader to put back a removed form, and the form they replace is still there. Docs move in the same changeset: `doc/h2_mux_internals.md`'s `ensure_tls_flushed`, `flush_pending_control_frames()`, `write_streams()` and `finalize_write()` sections, `h2_close.rs`'s module header, and LIFECYCLE.md's fourth-site paragraph. LIFECYCLE.md's `h2.rs:3336` pin drops to a bare `h2.rs` because the sentence holding it already names `finalize_write` -- #1509's form, and no line pin is reintroduced. The 35 remaining `h2.rs` line citations across LIFECYCLE.md, `doc/h2_mux_internals.md` and `doc/testing.md` are renumbered, and each one was checked twice: it lands on the byte-identical line text, and inside the identically-named enclosing item, that it named at 84d979f. That second key is what covers the generic anchors in the set -- `Position::Server => {`, `match error {`, and a `// RFC 9113 6.5` comment that exists in two different functions -- which text identity alone would pass. The drift gate exempts a re-anchored span from comparison, so it cannot tell a correct move from a wrong one; this audit is what does. The numbering was derived against 68523cc and holds unchanged at 84d979f: #1510 replaced exactly one `h2.rs` line and added none, so `git diff --numstat` over that range reads `1 1`, and the line it replaced (`H2ConnectionConfig::h2_initial_connection_window`'s doc comment) is named by no citation in the tree. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 24, 2026
…es at their flush points (#1512) `ConnectionH2::finalize_write` and `ConnectionH2::flush_pending_control_frames` were the last two core functions that read `ConnectionH2::tls_wants_write`, acted on the answer, and read it again. Both now answer a step and let the shell that owns the socket perform it, on the `poll_read_target` / `handle_read` protocol this module already uses for the read half. Issue #1339, Q10. `finalize_write` gains a leading `tls_wants_write: bool` and returns `H2FinalizeTarget`: `Done(MuxResult)` for the RFC 9113 6.8 graceful GOAWAY and the four readiness answers of LIFECYCLE 9 invariant 16, `Flush` / `SkipFlush` for the two that need the TLS step. `write_streams` -- already the only site that touches the socket on the stream-write path -- reads the query, performs `flush_tls_records` for `Flush` and not for `SkipFlush`, reads it again, and hands that second answer to the new `finalize_write_after_flush`. The two stay two variants rather than one boolean because `h2_close::finalize_action` already distinguishes them, and the post-flush read stays a second call rather than a reused binding because it asks a different question: not "does rustls hold records" but "did the step between them land" -- `socket_write(&[])`'s `(size, status)` is discarded, so nothing else on this path can tell. `flush_pending_control_frames` answers `H2ControlFlushTarget` instead of `Option<MuxResult>`. `Proceed` is the former `None`, `Done(MuxResult)` the former `Some`, and `Stalled` is new: the zero-buffer resume, the WINDOW_UPDATE drain and the RST_STREAM drain used to read `tls_wants_write` and call `ensure_tls_flushed` themselves, and now return `Stalled` for `writable` to do it once for all three. That query could not become an input -- it has to be read after the `flush_zero_to_socket` whose stall produced it, because that write is what changes the answer. `ensure_tls_flushed`'s production call sites fall from eight to six. `flush_zero_to_socket` stays inside the function: it is a byte mover on the control-frame path, not a TLS seam. Behaviour-preserving. `cargo test -p sozu-lib` reads `1115 passed; 0 failed` at 84d979f and `1115 passed; 0 failed` here; nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: `write_streams` reads `tls_wants_write` before `finalize_write` runs the graceful-GOAWAY check that used to precede the query, so on that path the query now happens and its value is discarded. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, and counts flushes only. The count of `self.socket` reaches above `mod tests` is unchanged at eleven, which is the honest measure of this step: neither function ever held one, both reached the socket only through the three named seams of #1499. Six `TO SEE THIS RED` recipes repaired, each applied as written and the failure recorded. Four named `self.socket.socket_wants_write()` at sites #1499 and touched anything: the WINDOW_UPDATE-drain and RST_STREAM-drain stages, and the `error_close_action` and `goaway_close_action` call sites in `writable`. A fifth named `self.socket.socket_write(&[])` in the GoAway arm's `CloseAction::Flush` body, which is `self.flush_tls_records()`. The sixth, on `a_finalized_write_pass_flushes_once_and_re_arms_while_records_survive`, this changeset itself made wrong. Measured: the two drain recipes and both halves of the finalize recipe give `1114 passed; 1 failed` naming only their own test, `error_close_action(false)` gives `1114 passed; 1 failed` (the stale text said `1097`), and the `goaway_close_action` post-flush constant and the deferred-GOAWAY-flush recipe each give `1113 passed; 2 failed` (the stale text said `1096`), the second failure being `a_flush_that_does_not_drain_keeps_the_connection_open`. The three `log_context!` recipes that name `self.socket` deliberately were read and left alone: they ask a reader to put back a removed form, and the form they replace is still there. Docs move in the same changeset: `doc/h2_mux_internals.md`'s `ensure_tls_flushed`, `flush_pending_control_frames()`, `write_streams()` and `finalize_write()` sections, `h2_close.rs`'s module header, and LIFECYCLE.md's fourth-site paragraph. LIFECYCLE.md's `h2.rs:3336` pin drops to a bare `h2.rs` because the sentence holding it already names `finalize_write` -- #1509's form, and no line pin is reintroduced. The 35 remaining `h2.rs` line citations across LIFECYCLE.md, `doc/h2_mux_internals.md` and `doc/testing.md` are renumbered, and each one was checked twice: it lands on the byte-identical line text, and inside the identically-named enclosing item, that it named at 84d979f. That second key is what covers the generic anchors in the set -- `Position::Server => {`, `match error {`, and a `// RFC 9113 6.5` comment that exists in two different functions -- which text identity alone would pass. The drift gate exempts a re-anchored span from comparison, so it cannot tell a correct move from a wrong one; this audit is what does. The numbering was derived against 68523cc and holds unchanged at 84d979f: #1510 replaced exactly one `h2.rs` line and added none, so `git diff --numstat` over that range reads `1 1`, and the line it replaced (`H2ConnectionConfig::h2_initial_connection_window`'s doc comment) is named by no citation in the tree. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 24, 2026
…cket shell `ConnectionH2::writable` held the last two query / flush / query triples inside the H2 core: an unconditional preamble flush whose post-flush answer the `(H2State::Error, Position::Server)` arm read, and a second, complete triple inside the `H2State::GoAway` arm. Both now follow the protocol #1512 established for `ConnectionH2::finalize_write` -- the core answers a step, the shell performs it, and the core is told what the socket then said. Issue #1339, Q10. `ConnectionH2::dispatch_writable_state(tls_wants_write: bool)` is `writable`'s `(H2State, Position)` match, arm for arm, and it answers `H2WritableStateTarget`: `Done(MuxResult)` for every arm that ends the pass, `Flush` for the one flush the GOAWAY arm needs, `WriteStreams` for the four proxying states. It takes no `Front`, no `Context` and no `Endpoint`, because no other arm reads either. `ConnectionH2::dispatch_writable_state_after_flush` is the GOAWAY arm's `TlsFlushPhase::AfterFlush` block with its `CloseAction::Disconnect => {}` fall-through spelled as the `force_disconnect` it fell through to. The two fused questions are two parameters of two functions. The GOAWAY arm's nested `if` asked "does rustls hold buffered records" and "did the kernel accept the flush" off two calls to the same query, and its own comment calls conflating them the primary truncation vector under HAProxy chaining: a proxy that closes a TLS connection with records pending sends FIN, destroys them, and the peer reads a truncated response it cannot distinguish from an attack. `Flush` therefore carries no `bool`. The pre-flush answer is `dispatch_writable_state`'s parameter, the post-flush answer is `dispatch_writable_state_after_flush`'s, and in the shell each read is its own `let` -- the third shadows the second inside the `Flush` arm alone. `H2FinalizeTarget` is not reused: its `SkipFlush` answers a question no close arm asks, since nothing writes to the socket between the dispatch and its flush, and sharing it would force a named-impossible arm into the shell's match -- `h2_close`'s own argument against widening `CloseAction`. `writable` moves into the shell impl block, which now holds `readable`, `writable` and `write_streams`. It performs every TLS seam call its own body used to make inline: the preamble flush and the two queries around it, the stalled-drain re-arm query, and the GOAWAY arm's flush and post-flush query. Two seam reads reached on the same pass stay outside it, and are named so the claim is exact -- the one inside `flush_zero_to_socket`, which `flush_pending_control_frames` still performs, and the one inside `force_disconnect`, `h2_close`'s third close site. `tls_wants_write`'s production call sites fall from 13 to 12, six of them in that block; `flush_tls_records` stays at 4 and `ensure_tls_flushed` at 6. `flush_pending_control_frames` keeps `flush_zero_to_socket`: a byte mover on the control-frame path is not a TLS seam, and lifting it is a different step. Behaviour-preserving. `cargo test -p sozu-lib` reads `1117 passed; 0 failed` at c5c8090 and `1117 passed; 0 failed` here; `sozu` 113, `sozu-e2e` 447 and `sozu-sim` 30 all pass, and nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: the Error and GOAWAY arms used to read `tls_wants_write` once each, and the shell now reads it once before the dispatch, so the query happens for the arms that never consulted it and its value is discarded there. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, deliberately so that no assertion pins the query count -- and the flush count per pass is unchanged, which is what its two `flushes.get() >= 2` assertions read. The net was run unchanged. The seven `FrontRustls` tests of #1454 and #1498, five of which build a real `ConnectionH2<FrontRustls>`, pass without an edit. Four `TO SEE THIS RED` recipes were repaired to name the functions the arms now live in, then applied as written and re-measured: deleting `ensure_tls_flushed` from `dispatch_writable_state_after_flush` gives `1116 passed; 1 failed` (`a_flush_that_does_not_drain_keeps_the_connection_open`); returning `Continue` after the `flush_tls_records()` in `writable`'s `H2WritableStateTarget::Flush` arm gives `1115 passed; 2 failed`; `error_close_action(false)` gives `1116 passed; 1 failed` (`a_rustls_frontend_in_error_state_re_arms_until_its_records_drain`); pinning `goaway_close_action(AfterFlush, false, ...)`'s third argument to `false` gives `1115 passed; 2 failed`. Each failed on the assertion message its recipe names. Their three stale `1113`/`1114` counts were measured against a 1115-test suite and are corrected. Docs move in the same changeset: `doc/h2_mux_internals.md`'s three-seams table, its `writable() entry point` section and both shell-impl-block claims, `h2_close.rs`'s module header and the docs on `goaway_close_action` and `error_close_action`, and LIFECYCLE.md's invariant 27. The seams table said 15 call sites for `tls_wants_write`: right at #1499, and #1512 folded two away without correcting the line. One comment in `h2.rs` called the Error arm's post-flush query Uncovered; that was already wrong before this changeset renamed what it points at, since #1454's rustls Error test drives it. The 50 `h2.rs` spans this changeset shifted were remapped by CONTENT -- `difflib.SequenceMatcher(autojunk=False)` equal-opcodes from c5c8090, never a global offset, never keyed on a basename -- and each was then audited on two keys: byte-identical line text, and an identically-named enclosing item. Zero mismatches over 74 compared endpoints. `doc/h2_mux_internals.md`'s `writable` signature block is the one span content could not map, because a 3 348-line move is a delete plus an insert and not an equal opcode; it was re-anchored by hand and its five quoted lines verified byte for byte. LIFECYCLE.md's `H2WritePhase::Resume` outbound-byte refresh dropped its number for the symbol instead, because the insertions moved it onto a line number another span already carried at the base revision, which the drift rule compares against whatever the base put there (#1447). Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 24, 2026
…cket shell `ConnectionH2::writable` held the last two query / flush / query triples inside the H2 core: an unconditional preamble flush whose post-flush answer the `(H2State::Error, Position::Server)` arm read, and a second, complete triple inside the `H2State::GoAway` arm. Both now follow the protocol #1512 established for `ConnectionH2::finalize_write` -- the core answers a step, the shell performs it, and the core is told what the socket then said. Issue #1339, Q10. `ConnectionH2::dispatch_writable_state(tls_wants_write: bool)` is `writable`'s `(H2State, Position)` match, arm for arm, and it answers `H2WritableStateTarget`: `Done(MuxResult)` for every arm that ends the pass, `Flush` for the one flush the GOAWAY arm needs, `WriteStreams` for the four proxying states. It takes no `Front`, no `Context` and no `Endpoint`, because no other arm reads either. `ConnectionH2::dispatch_writable_state_after_flush` is the GOAWAY arm's `TlsFlushPhase::AfterFlush` block with its `CloseAction::Disconnect => {}` fall-through spelled as the `force_disconnect` it fell through to. The two fused questions are two parameters of two functions. The GOAWAY arm's nested `if` asked "does rustls hold buffered records" and "did the kernel accept the flush" off two calls to the same query, and its own comment calls conflating them the primary truncation vector under HAProxy chaining: a proxy that closes a TLS connection with records pending sends FIN, destroys them, and the peer reads a truncated response it cannot distinguish from an attack. `Flush` therefore carries no `bool`. The pre-flush answer is `dispatch_writable_state`'s parameter, the post-flush answer is `dispatch_writable_state_after_flush`'s, and in the shell each read is its own `let` -- the third shadows the second inside the `Flush` arm alone. `H2FinalizeTarget` is not reused: its `SkipFlush` answers a question no close arm asks, since nothing writes to the socket between the dispatch and its flush, and sharing it would force a named-impossible arm into the shell's match -- `h2_close`'s own argument against widening `CloseAction`. `writable` moves into the shell impl block, which now holds `readable`, `writable` and `write_streams`. It performs every TLS seam call its own body used to make inline: the preamble flush and the two queries around it, the stalled-drain re-arm query, and the GOAWAY arm's flush and post-flush query. Two seam reads reached on the same pass stay outside it, and are named so the claim is exact -- the one inside `flush_zero_to_socket`, which `flush_pending_control_frames` still performs, and the one inside `force_disconnect`, `h2_close`'s third close site. `tls_wants_write`'s production call sites fall from 13 to 12, six of them in that block; `flush_tls_records` stays at 4 and `ensure_tls_flushed` at 6. `flush_pending_control_frames` keeps `flush_zero_to_socket`: a byte mover on the control-frame path is not a TLS seam, and lifting it is a different step. Behaviour-preserving. `cargo test -p sozu-lib` reads `1117 passed; 0 failed` at c5c8090 and `1117 passed; 0 failed` here; `sozu` 113, `sozu-e2e` 447 and `sozu-sim` 30 all pass, and nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: the Error and GOAWAY arms used to read `tls_wants_write` once each, and the shell now reads it once before the dispatch, so the query happens for the arms that never consulted it and its value is discarded there. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, deliberately so that no assertion pins the query count -- and the flush count per pass is unchanged, which is what its two `flushes.get() >= 2` assertions read. The net was run unchanged. The seven `FrontRustls` tests of #1454 and #1498, five of which build a real `ConnectionH2<FrontRustls>`, pass without an edit. Four `TO SEE THIS RED` recipes were repaired to name the functions the arms now live in, then applied as written and re-measured: deleting `ensure_tls_flushed` from `dispatch_writable_state_after_flush` gives `1116 passed; 1 failed` (`a_flush_that_does_not_drain_keeps_the_connection_open`); returning `Continue` after the `flush_tls_records()` in `writable`'s `H2WritableStateTarget::Flush` arm gives `1115 passed; 2 failed`; `error_close_action(false)` gives `1116 passed; 1 failed` (`a_rustls_frontend_in_error_state_re_arms_until_its_records_drain`); pinning `goaway_close_action(AfterFlush, false, ...)`'s third argument to `false` gives `1115 passed; 2 failed`. Each failed on the assertion message its recipe names. Their three stale `1113`/`1114` counts were measured against a 1115-test suite and are corrected. Docs move in the same changeset: `doc/h2_mux_internals.md`'s three-seams table, its `writable() entry point` section and both shell-impl-block claims, `h2_close.rs`'s module header and the docs on `goaway_close_action` and `error_close_action`, and LIFECYCLE.md's invariant 27. The seams table said 15 call sites for `tls_wants_write`: right at #1499, and #1512 folded two away without correcting the line. One comment in `h2.rs` called the Error arm's post-flush query Uncovered; that was already wrong before this changeset renamed what it points at, since #1454's rustls Error test drives it. The 50 `h2.rs` spans this changeset shifted were remapped by CONTENT -- `difflib.SequenceMatcher(autojunk=False)` equal-opcodes from c5c8090, never a global offset, never keyed on a basename -- and each was then audited on two keys: byte-identical line text, and an identically-named enclosing item. Zero mismatches over 74 compared endpoints. `doc/h2_mux_internals.md`'s `writable` signature block is the one span content could not map, because a 3 348-line move is a delete plus an insert and not an equal opcode; it was re-anchored by hand and its five quoted lines verified byte for byte. LIFECYCLE.md's `H2WritePhase::Resume` outbound-byte refresh dropped its number for the symbol instead, because the insertions moved it onto a line number another span already carried at the base revision, which the drift rule compares against whatever the base put there (#1447). Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 25, 2026
…cket shell (#1514) `ConnectionH2::writable` held the last two query / flush / query triples inside the H2 core: an unconditional preamble flush whose post-flush answer the `(H2State::Error, Position::Server)` arm read, and a second, complete triple inside the `H2State::GoAway` arm. Both now follow the protocol #1512 established for `ConnectionH2::finalize_write` -- the core answers a step, the shell performs it, and the core is told what the socket then said. Issue #1339, Q10. `ConnectionH2::dispatch_writable_state(tls_wants_write: bool)` is `writable`'s `(H2State, Position)` match, arm for arm, and it answers `H2WritableStateTarget`: `Done(MuxResult)` for every arm that ends the pass, `Flush` for the one flush the GOAWAY arm needs, `WriteStreams` for the four proxying states. It takes no `Front`, no `Context` and no `Endpoint`, because no other arm reads either. `ConnectionH2::dispatch_writable_state_after_flush` is the GOAWAY arm's `TlsFlushPhase::AfterFlush` block with its `CloseAction::Disconnect => {}` fall-through spelled as the `force_disconnect` it fell through to. The two fused questions are two parameters of two functions. The GOAWAY arm's nested `if` asked "does rustls hold buffered records" and "did the kernel accept the flush" off two calls to the same query, and its own comment calls conflating them the primary truncation vector under HAProxy chaining: a proxy that closes a TLS connection with records pending sends FIN, destroys them, and the peer reads a truncated response it cannot distinguish from an attack. `Flush` therefore carries no `bool`. The pre-flush answer is `dispatch_writable_state`'s parameter, the post-flush answer is `dispatch_writable_state_after_flush`'s, and in the shell each read is its own `let` -- the third shadows the second inside the `Flush` arm alone. `H2FinalizeTarget` is not reused: its `SkipFlush` answers a question no close arm asks, since nothing writes to the socket between the dispatch and its flush, and sharing it would force a named-impossible arm into the shell's match -- `h2_close`'s own argument against widening `CloseAction`. `writable` moves into the shell impl block, which now holds `readable`, `writable` and `write_streams`. It performs every TLS seam call its own body used to make inline: the preamble flush and the two queries around it, the stalled-drain re-arm query, and the GOAWAY arm's flush and post-flush query. Two seam reads reached on the same pass stay outside it, and are named so the claim is exact -- the one inside `flush_zero_to_socket`, which `flush_pending_control_frames` still performs, and the one inside `force_disconnect`, `h2_close`'s third close site. `tls_wants_write`'s production call sites fall from 13 to 12, six of them in that block; `flush_tls_records` stays at 4 and `ensure_tls_flushed` at 6. `flush_pending_control_frames` keeps `flush_zero_to_socket`: a byte mover on the control-frame path is not a TLS seam, and lifting it is a different step. Behaviour-preserving. `cargo test -p sozu-lib` reads `1117 passed; 0 failed` at c5c8090 and `1117 passed; 0 failed` here; `sozu` 113, `sozu-e2e` 447 and `sozu-sim` 30 all pass, and nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: the Error and GOAWAY arms used to read `tls_wants_write` once each, and the shell now reads it once before the dispatch, so the query happens for the arms that never consulted it and its value is discarded there. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, deliberately so that no assertion pins the query count -- and the flush count per pass is unchanged, which is what its two `flushes.get() >= 2` assertions read. The net was run unchanged. The seven `FrontRustls` tests of #1454 and #1498, five of which build a real `ConnectionH2<FrontRustls>`, pass without an edit. Four `TO SEE THIS RED` recipes were repaired to name the functions the arms now live in, then applied as written and re-measured: deleting `ensure_tls_flushed` from `dispatch_writable_state_after_flush` gives `1116 passed; 1 failed` (`a_flush_that_does_not_drain_keeps_the_connection_open`); returning `Continue` after the `flush_tls_records()` in `writable`'s `H2WritableStateTarget::Flush` arm gives `1115 passed; 2 failed`; `error_close_action(false)` gives `1116 passed; 1 failed` (`a_rustls_frontend_in_error_state_re_arms_until_its_records_drain`); pinning `goaway_close_action(AfterFlush, false, ...)`'s third argument to `false` gives `1115 passed; 2 failed`. Each failed on the assertion message its recipe names. Their three stale `1113`/`1114` counts were measured against a 1115-test suite and are corrected. Docs move in the same changeset: `doc/h2_mux_internals.md`'s three-seams table, its `writable() entry point` section and both shell-impl-block claims, `h2_close.rs`'s module header and the docs on `goaway_close_action` and `error_close_action`, and LIFECYCLE.md's invariant 27. The seams table said 15 call sites for `tls_wants_write`: right at #1499, and #1512 folded two away without correcting the line. One comment in `h2.rs` called the Error arm's post-flush query Uncovered; that was already wrong before this changeset renamed what it points at, since #1454's rustls Error test drives it. The 50 `h2.rs` spans this changeset shifted were remapped by CONTENT -- `difflib.SequenceMatcher(autojunk=False)` equal-opcodes from c5c8090, never a global offset, never keyed on a basename -- and each was then audited on two keys: byte-identical line text, and an identically-named enclosing item. Zero mismatches over 74 compared endpoints. `doc/h2_mux_internals.md`'s `writable` signature block is the one span content could not map, because a 3 348-line move is a delete plus an insert and not an equal opcode; it was re-anchored by hand and its five quoted lines verified byte for byte. LIFECYCLE.md's `H2WritePhase::Resume` outbound-byte refresh dropped its number for the symbol instead, because the insertions moved it onto a line number another span already carried at the base revision, which the drift rule compares against whatever the base put there (#1447). 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.
Refs #1339. Step one of seven toward the byte-in / byte-out core.
Q10 decided that
ConnectionH2loses itsFront: SocketHandlerparameter and rustls moves to an I/O shell. That is not one changeset — so the first deliverable was a sequencing plan, and this is its first step.Plan:
Projects/sozu/2026-09-24 H2 Socket Boundary Extraction Sequencing.mdin the knowledge vault, linked from the umbrella extraction plan and the sozu index.The 26 reaches, classified
grep -c self.socketoverh2.rsreturns 40, but 12 of those are inmod tests. The production range holds 26 code occurrences, and they are not one problem:readable'ssocket_read,write_streams'socket_write_vectored,flush_zero_to_socket's realsocket_write. All three already sit outside the pure cores.Debugimpl'ssocket_ref(), andsnapshot_rtts'socket_rtt. These are the onlysocket_ref()reaches;socket_mut()is unreached.socket_wants_write()×16, empty-buffersocket_write(&[])×4,socket_close()×1. Their policy was already extracted intoh2_close; only the queries and the flush were inline.Q11 turns out to be half-shipped:
Endpoint::socketno longer exists —Endpoint::peer_rttreplaced it. Only the localclient_rtthalf remains.This step
ConnectionH2reaches TLS through three private seams —tls_wants_write,flush_tls_records,begin_tls_close— instead of 21 raw calls. Productionself.socketgoes 26 → 8.One non-substitution, recorded rather than smoothed over:
force_disconnectreads the answer once above itsmatch, because a&selfmethod cannot coexist with the&mut self.positionthe client arm holds. That is why 16 reaches became 15 calls.No step in the series leaves two ownership models coexisting — the socket stays on
ConnectionH2until S7 moves it once.Red-then-green found a total coverage gap
No behaviour change means no new test, so coverage was proved by mutating each seam:
sozu-libtls_wants_write() -> false1097 passed; 10 failedflush_tls_records()no-op1103 passed; 4 failedbegin_tls_close() -> {}1107 passed; 0 failedThe third also leaves
sozu-e2eat447 passed; 0 failed. Nothing anywhere drives the TLS close-notify path, althoughMux::shutting_downreaches it in production. #1484's coverage audit independently listed the same site from the other direction.Filed as #1498 and deliberately not closed here — it needs a driven
close_notifyand its own test, which is different work from a boundary extraction.#1484's six
ConnectionH2<FrontRustls>tests: 0 diff hits each, all six green, shape unchanged. Those are the tests that cover thesize > 0 && WouldBlocktruncation vector, which is the defect class this boundary work most risks reintroducing.Where the rest of the programme sits
S7 is the step that frees the simulator: #1485's harness holds
Connection<SimSocket>, soSimSocketmust be aSocketHandler, andsocket_ref/socket_mutreturn&mio::net::TcpStream— the sole reason for its placeholder loopback stream and itsmiodev-dependency. At S7 it constructsConnectionH2directly and both disappear.An earlier alternative — relaxing those two to
Option— would free it after S2, but touches the nine files carryingFront: SocketHandlerbounds for a benefit S7 deletes. Rejected and recorded.For the dependent issues: #1340's Q6 needs S7 and nothing else, Q7 needs nothing, Q12 needs S7 for the embedder to exist. #1341's recorded blocker is already satisfied — "Q11's answer changes the trait Q4's accounting travels through" refers to
Endpoint, andsocket→peer_rtthas shipped. Q4 still needs S7, because itsDrop-time gauge rebalance moves onto the shell wrapper S7 creates.One finding that qualifies the recorded decision
Injecting
client_rttper pass is 2–5× the current per-recyclegetsockopt(TCP_INFO)rate, andEndpointcannot supply it lazily — it is the other side of the connection. Two acceptable resolutions are named in the plan: measure per-pass injection before merging S2b, or express it as access-log output per #1340's Q4 shape. S2b sequences with or after that decision.Verification
No public signature changed; three private methods added. Reference sweep dispositioned every hit — notably
h2_close.rs's pre-existingtls_wants_writeparameter isunaffected — different symbol, already the decision module's input name.63 exempt citation spans, all audited: 8 pinned blocks re-anchored by content, ~50 prose citations via an exact
git diff -U0line map, then every one of the 63 compared against its baseline pre-image — 63/63 byte-identical, 0 differ, 0 unmappable.No manifest or lockfile change, no
async fn, no#[allow]/#[expect]/-A, no#[ignore], no test removed.Conflict, reported not resolved
Against
refactor/h2-ordered-backends(the #1338 determinism slice): exactly one conflict,CHANGELOG.md, with an empty diff3 base region — both sides inserted disjoint entries at the same anchor. The branches share no source file. Both entries are wanted and the order is editorial.