Repository navigation
test(mux-h2): drive a real TLS close_notify and assert the peer decrypts it - #1508
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 13:50
FlorentinDUBOIS
force-pushed
the
test/h2-close-notify-coverage
branch
from
September 24, 2026 15:54
ed6f068 to
7335ffa
Compare
`ConnectionH2::begin_tls_close` reaches `FrontRustls::socket_close`, which is `rustls::ServerConnection::send_close_notify`. It had no coverage at all. Measured at 0dddedf: replacing its body with `{}` left `cargo test -p sozu-lib` at `1114 passed; 0 failed` and reddened no `sozu-e2e` test either, while the same mutation on either of its two siblings from the same extraction reddens at once. Measured against this changeset's own `1115 passed` baseline: `tls_wants_write() -> false` gives `1104 passed; 11 failed` and a no-op `flush_tls_records()` gives `1110 passed; 5 failed`, ten and four of those respectively being tests other than the one added here. The hole was structural rather than an oversight. Every handler the suite drove a close over -- `mio::net::TcpStream` and the `BackpressuredTlsSocket` fixture -- inherits `SocketHandler::socket_close`'s empty trait default, so the real seam and a no-op are the same thing to all of them, and `FrontRustls` is the only implementation in the tree that overrides it. #1484's coverage audit reached the same conclusion from the other direction, listing `initiate_close_notify` among the `socket_wants_write` branches its six `ConnectionH2<FrontRustls>` tests could not reach, for want of a driven close_notify. `a_frontend_timeout_makes_the_peer_receive_a_tls_close_notify` drives the production route end to end over the existing `rustls_h2_connection` fixture: `Mux::timeout` -> `Mux::delay_close_for_frontend_flush` -> `Connection::initiate_close_notify` -> `ConnectionH2::initiate_close_notify` -> `begin_tls_close` -> `send_close_notify`, then flushes through the same `Connection::flush_zero_buffer` that `Mux::shutting_down_inner` calls for this purpose. It asserts on what the peer's real `rustls::ClientConnection` decrypts: `IoState::peer_has_closed()`, and `Reader::read` answering `Ok(0)` rather than `UnexpectedEof`. That second witness is the whole point -- rustls answers `Ok(0)` only for a stream closed with a close_notify and `UnexpectedEof` for a bare FIN, so an assertion that a FIN had arrived would have passed against the mutant. Seen red before it was trusted: `1114 passed; 1 failed`, this test and nothing else, failing on `the peer must decrypt a TLS close_notify alert`. Test-only. The whole diff lies inside `#[cfg(test)] mod tests`, so `sozu-lib` built as a dependency is byte-identical to 0dddedf and no `sozu-e2e` behaviour can change. Refs: #1498 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
test/h2-close-notify-coverage
branch
from
September 24, 2026 17:00
7335ffa to
4345dd6
Compare
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.
What
Closes #1498.
ConnectionH2::begin_tls_closeis the seam that reachesFrontRustls::socket_close, which isrustls::ServerConnection::send_close_notify. It had zero coverage. This adds one test thatdrives a real
close_notifyover a realFrontRustlsand asserts on the bytes the peer decrypts.Test-only: the entire diff sits inside
#[cfg(test)] mod tests(one hunk ath2.rs:13333; themodule opens at 6779).
sozu-libbuilt as a dependency is byte-identical to0dddedf2, so nosozu-e2eorsozu-simbehaviour can change.The gap, reproduced
Mutating
begin_tls_closeto{}on a detached0dddedf2:cargo test -p sozu-libat0dddedf2(baseline 1114)tls_wants_write() -> falseflush_tls_records()no-opbegin_tls_close()->{}The two sibling rows were measured on this branch (baseline
1115 passed), where they read1104 passed; 11 failedand1110 passed; 5 failed; the counts above subtract the one failurethat is the test added here. Every row is self-consistent against its own baseline.
begin_tls_closealso reddened nosozu-e2etest on the mutation. That cell was re-measuredon a mutated pristine
0dddedf2in a verified-quiet window:447 passed; 0 failed; 4 filtered out, first try. The earlier446 passed; 1 failedreading at42ed6bac, whose single failure was the load-inducedtest_redirect_permanent_h2_skips_backend, no longer carries the claim.The hole is structural, not an oversight. Every handler the suite drove a close over —
mio::net::TcpStreamand theBackpressuredTlsSocketfixture — inheritsSocketHandler::socket_close's empty trait default, so the real seam and a no-op areindistinguishable to all of them.
FrontRustlsis the only implementation in the tree thatoverrides it.
#1484's coverage audit reached the same conclusion from the other direction, listing
initiate_close_notifyamong thesocket_wants_writebranches its sixConnectionH2<FrontRustls>tests could not reach — reason: "needs a driven TLS close_notify".The test
a_frontend_timeout_makes_the_peer_receive_a_tls_close_notify, built on the existingrustls_h2_connection/handshaken_front_rustlsfixture from #1484/#1491. It drives theproduction route end to end:
then flushes with the same
Connection::flush_zero_bufferthatMux::shutting_down_innercallsfor exactly this purpose, on a connection whose zero buffer is empty so nothing but the alert
reaches the wire.
The assertion is on what the peer's real
rustls::ClientConnectiondecrypts, not on a FIN:IoState::peer_has_closed()— true only once aclose_notifyalert has been processed;Reader::readansweringOk(0)— rustls'scheck_no_bytes_stateyieldsOk(0)only for astream closed with a
close_notify,UnexpectedEof("peer closed connection without sending TLS close_notify")for a bare FIN, andWouldBlockfor neither;received.is_empty()— no application plaintext accompanied the alert.That second witness is the point. An assertion that a FIN had arrived would have passed against
the mutant, which still closes the socket. Likewise,
close_notify_sentis still set by themutant, so no assertion on that flag could discriminate — only the bytes the peer receives can.
Seen red before it was trusted. With
begin_tls_closemutated to{}on this branch:Restored and re-run:
test result: ok. 1115 passed; 0 failed. Both cycles were run on the exactbytes that ship, and the restore was proved byte-identical by md5
(
916da773316f2ec9df8352b269619b52before and after).Correction to the issue's reachability claim
#1498 says
ConnectionH2::initiate_close_notify"is reached fromMux::shutting_downviaself.frontend.initiate_close_notify()". It is not.Mux::delay_close_for_frontend_flush(
mux/mod.rs:966) is the sole caller ofConnection::initiate_close_notify, and it is itselfcalled from five sites — four in
Mux::ready_inner(frontend HUP, frontend readable-close,backend close, frontend writable-close) and one in
Mux::timeout_inner.Mux::shutting_down_innernever asks for the alert; it drives frontend I/O and flushes recordsthe alert has already generated, which is why
flush_zero_bufferis the right flush to use here.The timeout site was chosen over the four
ready_innerones only because those need aRc<RefCell<dyn ProxySession>>and adyn L7Proxy; the seam under test is identical on all five.Not included: the H1-mirroring
debug_assert!s — blockedConnectionH1::initiate_close_notifyguards two invariants that H2 guards neither of, andmirroring them onto H2 was intended here. It is blocked by line-pinned documentation
citations, not by disagreement — the patch is written, tested and reverted:
Those lines (shown trimmed of their explanatory comments; 21 lines as written) land at
h2.rs:1416, which shifts every cited line below them and reddenspython3 .github/scripts/check_doc_citations.py --root .on nine citations:lib/src/protocol/mux/LIFECYCLE.md:1342— invariant 8 citesh2.rs:4874-4881(andh2.rs:6699-6706); after the shift4874is blank. The companion6699-6706drifts ontodifferent non-blank lines and silently resolves, which is exactly the floor the script's own
output warns about.
doc/h2_mux_internals.md— 8 pinned code blocks (lines 536, 560, 592, 657, 744, 1054, 1207,1215) whose strict content match fails on any shift.
Both files are being worked on concurrently, so repointing them here would collide — and
checking those branches shows the blocker survives their merge, so this is not simply a
"wait for them" follow-up:
docs/lifecycle-citation-repair(07574ad1) still spells invariant 8 with line numbers,merely renumbered:
`h2.rs:4922-4930`, `h2.rs:6681-6689`.docs/h2-mux-internals-snippet-sweep(92c9ea75) carries 17 pinnedh2.rs:NNNblocks,up from 13 at
42ed6bac.So landing the assertions needs its own step, ordered after both merge: repoint whatever the
pinned blocks and invariant 8 then say, or — better — convert invariant 8 to symbols. Shrinking the
assertions until
4874happens to land on a non-blank line would make the citation resolve to thewrong code, which is gaming the gate rather than fixing it. The assertions add no discriminating
power to the test above, so dropping them costs this changeset nothing.
Worth noting while the citation work is in flight:
LIFECYCLE.mdinvariant 7, immediatelyabove, ends with "Cited by symbol rather than by line on purpose … Do not convert it back." —
while invariant 8 directly beneath it is line-pinned into
h2.rstwice, andCLAUDE.mdstatesthe repo rule as "A citation in a comment names a symbol, never a line." Converting invariant
8's two citations to symbols (
ConnectionH2::create_stream,ConnectionH2::start_stream) wouldunblock this and every future insertion into
h2.rs. Reported, not fixed, per scope.Validation
All on
4345dd68:cargo +nightly fmt --all -- --checkcargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simdcargo clippy --all-targets … -- -D warningscargo test -p sozu-lib …cargo test -p sozu …cargo test -p sozu-e2e … --skip tests::fuzz_tests::RUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --lockedRUSTFLAGS="--cfg tokio_unstable" cargo clippy -p sozu-sim --all-targets -- -D warningscheck_doc_citations.py --root .check_doc_citations.py --base 0dddedf2RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --lockedcargo bench -p sozu-lib --bench h2_stream_table -- --testSuccess)Test-environment note (not a regression)
The e2e suite was run six times on this box while other work saturated it. At loadavg 40–50 it
reddened with a different test each time; at loadavg ≤ 20 it is green:
test_issue_806,test_upgrade_keepalive_reconnecttest_asynctest_h2_continuation_survives_a_graceful_drain_mid_reassembly42ed6bactest_redirect_permanent_h2_skips_backendEvery one of those tests passes 3/3 when run isolated. The rotating cast (rather than a fixed
test), the green runs at low load, and the fact that a base-derived tree reddened the same way
all point at host contention.
test_issue_806reports its own cause —reconnecting to another backend took 201.01866ms, over the 100ms budget. Base was never run atloadavg ≥ 40, so that gap is why the decisive argument is the machine property: the shipped diff
is entirely inside
#[cfg(test)] mod tests, which is not compiled into a dependency build, so thesozu-libthatsozu-e2elinks is source-identical to0dddedf2.