Skip to content

refactor(mux-h1): render the peer address in ConnectionH1's Debug - #1542

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
refactor/h1-debug-peer-address
Sep 26, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
refactor/h1-debug-peer-address

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

The divergence, measured

ConnectionH1's Debug rendered .field("socket", &self.socket.socket_ref()).
socket_ref() returns the raw mio::net::TcpStream, so that field handed the
OS type's own Debug a local address, a live getpeername(2) taken at format
time
, and a file descriptor. Measured against 274268af, on a frontend
connection whose handler declares 10.0.0.42:12345:

ConnectionH1 { position: Server, readiness: Readiness { interest: R-EH, readiness: ----, mixed: ---- }, socket: TcpStream { addr: 127.0.0.1:34880, peer: 127.0.0.1:33567, fd: 4 }, stream: Some(0), reused_from_pool: false }

The declared address appears nowhere; the kernel's does, twice, beside a
descriptor that names nothing outside this process.

Swept at 274268af: lib/src/protocol/mux/ holds four debug_struct
sites — ConnectionH1 (h1.rs), ConnectionH2 (h2.rs), Kawa and Stream
(stream.rs) — and ConnectionH1 was the only one still naming the raw socket.
ConnectionH1 already carried peer_address: Option<SocketAddr>, snapshotted
once by Connection::new_h1_server / Connection::new_h1_client from
SocketHandler::peer_addr, which prefers the PROXY-protocol-declared address
and survives a peer reset. Every log_context! line of the same connection
already renders it, so one session ULID rendered two different peers depending
on whether a trace carried the struct or a log line.

The form retained, and why it is ConnectionH2's

ConnectionH2's Debug was checked first, as asked. It keeps no socket field
at all
— it renders .field("peer_address", &self.peer_address) and nothing
else about the transport, because ConnectionH2 shed its Front parameter to
H2Shell entirely. So the symmetric change is a straight in-place swap, same
field name, same slot between readiness and stream, no reordering and no
third variant:

-            .field("socket", &self.socket.socket_ref())
+            .field("peer_address", &self.peer_address)

One line, and deliberately line-count-neutral: kawa_h1/LIFECYCLE.md and
mux/LIFECYCLE.md carry live h1.rs:NNN citations, and shifting them would
both redden check_doc_citations.py --base and drag mux/LIFECYCLE.md — a file
one in-flight PR already edits — into this diff. The rationale therefore lands
in doc/h2_mux_internals.md's existing "What the Debug impl renders" section,
which nothing cites by line, rather than in a header comment mirroring H2's.
That section's third reason is recorded there as not transferring:
ConnectionH1 keeps Front: SocketHandler, so this is the rendering half of
the H2 change and none of its extraction half.

socket_ref() code reaches in h1.rs's production range go 4 to 3;
socket_mut() stays at 0. The three survivors are the stats::socket_rtt
samples in ConnectionH1::writable, still at lines 739, 791 and 814 — they read
a round-trip time, not an address, and are untouched.

To SEE THIS RED

In impl Debug for ConnectionH1 (lib/src/protocol/mux/h1.rs), put

            .field("socket", &self.socket.socket_ref())

back in place of

            .field("peer_address", &self.peer_address)

then run

cargo test -p sozu-lib --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd \
  -- protocol::mux::h1::tests::debug_renders_the_proxy_advertised_peer_not_the_transport_socket --exact

The replaced literal is present in the tree at this branch's head, so the recipe
is replayable. Observed on the reverted tree: running 1 test →
test result: FAILED. 0 passed; 1 failed; 1147 filtered out, panicking on
the ConnectionH1 Debug must render the declared peer: with the struct quoted
above. Restored: 1 passed. Driven twice — red, green, red, green — with the
production file restored by cmp-verified copy each time, never git stash
(the worktree is shared).

The test pins the value, not a count: it builds the connection over a
genuinely connected loopback socket, asserts first that the live lookup is
healthy and disagrees with the declared address (so it cannot pass for the wrong
reason), then asserts {:?} carries Some(10.0.0.42:12345) and not the
transport address. Both assertions name addresses only, so they share no literal
with the production diff — the swept peer_address / socket_ref /
debug_struct / .field tokens appear in this changeset's test only inside the
doc comment's recipe, never inside an assertion.

Battery

All against this branch's head, exit codes read directly rather than through a
pipe.

Step Result
cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd 0
cargo +nightly fmt --all -- --check 0
cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings 0
cargo test -p sozu-lib … 0 — 1148 passed, 0 failed; the base measures 1147 in a throwaway worktree at 274268af, and this diff adds exactly one #[test] and removes none
cargo test -p sozu … 0 — 113 passed
cargo test -p sozu-command-lib --locked 0 — 171 + 4 + 2 passed
cargo test -p sozu-e2e … -- --skip tests::fuzz_tests:: 0 — 449 passed, 0 failed
RUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --locked 0 — 12 + 6 + 6 + 6 passed
RUSTFLAGS="--cfg tokio_unstable" cargo clippy -p sozu-sim --all-targets --locked -- -D warnings 0
check_doc_citations.py --self-test 0
check_doc_citations.py --root . 0
check_doc_citations.py --base 274268af637c847ff8a84bb5cb57a6bc9b1a740a 0 — no citation drift, 0 spans exempted
check_doc_citations.py --audit --root . 0
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked 0

sozu-e2e ran behind a three-criterion gate evaluated in the same command as the
launch — LOAD1=6.46 (< 8), CHILD=0, PARENT=0, the parent probe anchored on
rustup/toolchains/*/bin/cargo so the guard cannot count its own shell.

No check was weakened: nothing skipped or ignored, no assertion relaxed, no
clippy allow, no lowered -D warnings. No async fn enters lib/ or bin/,
and no production dependency changes.

Scope

Three files: lib/src/protocol/mux/h1.rs (the one-line swap plus the regression
test), doc/h2_mux_internals.md (the Debug contract, now stated for both
impls), CHANGELOG.md (entry appended at the end of [Unreleased]'s
🔄 Changed, beside the refactor(mux-h2) twin, to avoid a head-insertion
adjacency collision). The only expected overlap with the two
in-flight pull requests is CHANGELOG.md — neither touches h1.rs. Rebased on
274268af and swept for conflict markers on all four zdiff3 forms.

This changeset references no issue for closure.

Signed-off-by: Florentin Dubois [email protected]

ConnectionH1's Debug was the last one in protocol/mux/ still naming the raw
socket: of the module's four debug_struct sites it alone handed
mio::net::TcpStream's own Debug a local address, a live getpeername(2) taken at
format time, and a file descriptor.

.field("socket", &self.socket.socket_ref()) becomes
.field("peer_address", &self.peer_address) — the same field name, in the same
slot, that ConnectionH2's Debug already renders. peer_address is the snapshot
Connection::new_h1_server and Connection::new_h1_client each take once from
SocketHandler::peer_addr, and it is the source every log_context! line of the
same connection already renders, so until now one session ULID rendered two
different peers depending on whether a trace carried the struct or a log line.
It drops the descriptor, which named nothing outside this process; it survives
the peer's reset, where the live lookup answers ENOTCONN on exactly the error
lines an operator reads during an incident; and on a PROXY-protocol frontend it
names the client the header advertised rather than the load balancer the
transport is connected to.

socket_ref() code reaches in h1.rs's production range go 4 to 3, and
socket_mut() stays at 0. The three survivors are the stats::socket_rtt samples
in ConnectionH1::writable: they read a round-trip time rather than an address
and are deliberately untouched. Unlike ConnectionH2, which shed its Front
parameter to H2Shell, ConnectionH1 keeps Front: SocketHandler — this is the
rendering half of that change and none of its extraction half.

Seen red before it was trusted, on the value rather than on a field name or a
count. debug_renders_the_proxy_advertised_peer_not_the_transport_socket builds a
frontend connection over a genuinely connected loopback socket whose
SessionTcpStream declares 10.0.0.42:12345, asserts first that the live lookup is
healthy and disagrees with that declaration, then asserts on what {:?} renders.
Against the pre-fix impl it fails with
socket: TcpStream { addr: 127.0.0.1:34880, peer: 127.0.0.1:33567, fd: 4 } and
the declared address nowhere in the line. sozu-lib goes 1147 to 1148 tests;
every other suite is unmoved.

doc/h2_mux_internals.md's Debug section now states the contract for both impls,
including the one reason that does not transfer to H1.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the refactor/h1-debug-peer-address branch from ef5f2f0 to 9e4f1cb Compare September 25, 2026 23:39
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 4cbad82 into main Sep 26, 2026
28 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the refactor/h1-debug-peer-address branch September 26, 2026 00:41
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