Repository navigation
refactor(mux-h2): hand ensure_tls_flushed the TLS answer instead of asking - #1507
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 13:39
FlorentinDUBOIS
force-pushed
the
refactor/h2-tls-query-injection
branch
2 times, most recently
from
September 24, 2026 16:06
eb93084 to
5456ed6
Compare
…sking `ConnectionH2::ensure_tls_flushed` read `self.tls_wants_write()` itself, so each of its eight call sites paid a socket query the composite could not see was already answered. Five of them had the answer in hand. For four, the re-arm is the second half of a decision `h2_close` had just taken on that very value: `finalize_action`'s `AfterFlush` phase, `error_close_action`, `goaway_close_action`'s `AfterFlush` phase, and `force_disconnect`, which already bound the answer above its `match`. The fifth, `initiate_close_notify`, reaches no `h2_close` decision at all — its branch condition is the answer. Nothing mutates the socket in between at any of the five, so the second query could only repeat the first; all five now pass the binding they hold and the helper takes a `tls_wants_write: bool`. The three stalled-drain tails of `flush_pending_control_frames` keep a query, now spelled at the call site rather than borrowed from the helper. They run after the `flush_zero_to_socket` whose stall brought them there, and that write is exactly what changes the answer, so a value bound before the call would be the wrong one. The helper's doc states which callers are in which group and why, so the asymmetry is read where it lives. Two sibling helpers deliberately keep their own query. `ConnectionH2::has_pending_write` is `pub`, `Connection` dispatches it through `forward!`, and that macro's H1 arm *is* `socket_wants_write()`, so handing it a parameter means widening the seam's visibility and reaching the socket from `connection.rs` and from the simulator — growing the out-of-file query surface the named seams were introduced to shrink. `ConnectionH2::flush_zero_to_socket` reads it only inside a per-iteration `#[cfg(debug_assertions)]` trace taken after each `socket_write`, where a caller-supplied value would log the pre-flush answer: the stale `wants_write=` that `force_disconnect`'s own comment forbids. No behaviour change, and the counts say so. `cargo test -p sozu-lib` is unmoved at 1113 passed, `sozu` at 113, `sozu-e2e` at 447 and `sozu-sim` at 12/6/6/6. The coverage guard is unmoved too: replacing `ConnectionH2::tls_wants_write`'s body with `false` yields `1103 passed; 10 failed` before this change and the same ten test names after it, among them the two stalled-drain tests whose query moved out to the caller — which is what proves the seam is still wired to its callers rather than quietly decoupled from them. 52 of the 57 `h2.rs` citation numbers these three documents carry were re-anchored by the line shift — exactly the 52 spans `check_doc_citations.py --base` exempts from its own comparison and never checks. Every cited span was then compared against its pre-image slab by slab: interiors included and not only the endpoints `--base` lists, and against both sides of the merge rather than one — 89 spans, 37 of them multi-line ranges, 1372 source lines, all byte-identical. Each of the 52 exempt spans was then read by hand against the statement its prose names. Refs #1339 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
refactor/h2-tls-query-injection
branch
from
September 24, 2026 16:13
5456ed6 to
d666317
Compare
This was referenced Sep 24, 2026
Closed
Merged
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.
ConnectionH2::ensure_tls_flushedreadself.tls_wants_write()itself, so each of its eight call sites paid a socket query the composite could not see was already answered. It now takestls_wants_write: bool.Five callers already held the answer. For four, the re-arm is the second half of a decision
h2_closehad just taken on that very value —finalize_action'sAfterFlushphase,error_close_action,goaway_close_action'sAfterFlushphase, andforce_disconnect, which already bound it above itsmatch. The fifth,initiate_close_notify, reaches noh2_closedecision at all: its branch condition is the answer. Nothing mutates the socket in between at any of the five, so the second query could only repeat the first.The three stalled-drain tails of
flush_pending_control_frameskeep a query, now spelled at the call site rather than borrowed from the helper: they run after theflush_zero_to_socketwhose stall brought them there, and that write is exactly what changes the answer, so a value bound before the call would be the wrong one. The helper's doc records which callers are in which group and why.What this removes is five runtime re-queries, not source occurrences. Production
self.tls_wants_write()occurrences go 13 → 15: the helper's own read is deleted, and the three stalled-drain tails each spell their own. The saving is at runtime, on the five paths where the answer was already in hand.Scope
This is one helper of the three the socket-boundary sequencing originally grouped here, and the narrowing is deliberate rather than partial work:
ConnectionH2::has_pending_writekeeps its own query and moves to the step where the shell owns the socket. It ispub,Connectiondispatches it throughforward!, and that macro's H1 arm issocket_wants_write()— parameterising it means widening the seam's visibility and reaching the socket fromconnection.rsand from the simulator, growing the out-of-file query surface the named TLS seams were introduced to shrink.ConnectionH2::flush_zero_to_socketkeeps its own too, and moves with the byte movers. Its only read sits inside a per-iteration#[cfg(debug_assertions)]trace taken after eachsocket_write; a caller-supplied value would log the pre-flush answer — the stalewants_write=thatforce_disconnect's own comment forbids, on the truncation diagnostic itself.Six files touched:
h2.rs,h2_close.rs(the```ignoreexample),doc/h2_mux_internals.md,doc/testing.md,LIFECYCLE.md,CHANGELOG.md. Noconnection.rs, noh1.rs, nosim/, noforward!change, no visibility change totls_wants_write.No behaviour change, and the counts say so
Against a baseline measured on a detached
d192407bworktree:sozu-lib1113,sozu113,sozu-e2e447,sozu-sim11/6/6/6 — every one unmoved.fmt --check,clippy --all-targets -D warnings,clippy -p sozu-simunder--cfg tokio_unstable,cargo docwithRUSTDOCFLAGS="-D warnings", andcargo bench -p sozu-lib --bench h2_stream_table -- --testall exit 0.The coverage guard is unmoved too
Replacing
ConnectionH2::tls_wants_write's body withfalseyields1103 passed; 10 failedon the tree before this change and the same1103 passed; 10 failedafter it — over an identical set of ten test names, diffed, not merely an identical count.Two of the ten are
a_stalled_window_update_drain_re_signals_the_writable_eventanda_stalled_rst_stream_drain_re_signals_the_writable_event— the stages whose query moved out to the caller. That is what shows the seam is still wired to its callers rather than quietly decoupled from them, which is the one way a refactor like this could be silently wrong while every test stays green.#1484's six
ConnectionH2<FrontRustls>tests are byte-unchanged and green, proven structurally rather than by a green run: every hunk inh2.rsends at or below line 8007, and that block starts at 12497.Citations
45 doc citations into
h2.rswere re-anchored by the line shift, mapped through an exact old→new table built fromdifflibequalopcodes againstd192407b. 0 unmapped. The opcode list doubled as a scope check: exactly 17 changed regions, every one accounted for.Every cited span was then compared against its pre-image slab by slab, interiors included — not only the endpoints
check_doc_citations.py --base --showlists. A range whose two endpoints both land inequalblocks can still straddle an edit in its interior, so an endpoint-only audit is not sufficient. 50 citations, 20 of them multi-line ranges, all byte-identical. That covers the 63 re-anchored spans the check exempts from its own comparison and never looks at.CHANGELOG placement
Unreleased had no
### ➖ Removedsection; this opens one immediately before### 🔐 Security. The✨ Added,🔄 Changedand🐛 Fixedheadings stay at lines 5, 211 and 1406 — unmoved — so no other in-flight changeset's insertion anchor shifts.Known stale, deliberately not touched
Four
TO SEE THIS REDrecipes still sayself.socket.socket_wants_write(), which #1499 already replaced in production:h2.rs:8260and:8328(the WINDOW_UPDATE and RST_STREAM drain stages),:13197(error_close_action),:13284(goaway_close_action's third argument). Stale before this change, so left under the no-tidying rule — two of them describe stages this commit edits, so they are now doubly stale. They belong with S4, which touches the same drain stages.Refs #1339