Repository navigation
Description
MUX-H1 renders its peer= field with a live getpeername(2) that reaches past SocketHandler::peer_addr(), the trait method added precisely to stop that. This is the same defect #1341's Q5 fixed for MUX-H2 in #1360, left behind on the H1 side.
Found while auditing whether Q5 still held after #1501; it does, and this is what the audit turned up next to it.
The two sites
Both are in lib/src/protocol/mux/h1.rs, in the two log-context macros, and both are production:
h1.rs:56—log_context!h1.rs:85—log_context_stream!
Both read:
peer = $self.socket.socket_ref().peer_addr().ok(),$self.socket is Front: SocketHandler, so the trait method is in scope and available. The macro goes around it to the raw stream instead.
For contrast, the H2 macros at h2.rs:91 and h2.rs:125 read peer = $self.peer_address, a field on ConnectionH2 (h2.rs:720) seeded once per connection from socket.peer_addr() in H2Shell::new. ConnectionH1 has no equivalent field.
33 expansions of the two macros exist in h1.rs.
Why it matters, and what it costs
The reasons are #1341's, unchanged, and they are about observability rather than performance:
getpeernamereturnsENOTCONNafter a peer RST, so theerror!lines an operator reads during an incident renderpeer=None— on H1 today, where H2 now renders the address.- On a PROXY-protocol frontend the cached value is the advertised client; a live lookup is the load balancer.
FrontRustls::peer_addrreturnsconfigured_peer, seeded fromHttpsSession::peer_addressathttps.rs:562, which is exactly what makes the PROXY case correct — and the H1 macro does not consult it. SessionTcpStream::peer_addris cache-then-live for backend-connect failures; the H1 macro bypasses that too.
So for the same connection, an operator grepping one ULID can currently get a correct peer= on a MUX-H2 line and peer=None, or the load balancer's address, on a MUX-H1 line.
Do not argue this on performance. #1341 examined that for H2 and retracted it: there is no clock read in the macro, no expansion is unconditional per-frame or per-request, and _log_enabled! returns before the arguments are evaluated, so a filtered line pays nothing. The same reasoning applies here and the same conclusion should be drawn — the case is observability and consistency, nothing else.
Two possible fixes, and they are not equivalent
- Call the trait method. Replace both expressions with
SocketHandler::peer_addr(&$self.socket). Two lines. Fixes the PROXY and cache-then-live cases immediately, because those live inside the implementors. - Cache per connection, as H2 does — a
peer_addressfield onConnectionH1seeded once at construction. Larger, and it is what makes the H2 field read structurally incapable of returningENOTCONNrather than merely unlikely to.
(1) is the floor and closes most of the gap. (2) is what H2 ended up with, and only after 4eb51741, the first commit of #1471, hoisted the per-expansion call into a connection-owned field. Whether H1 should go straight there is a judgement about whether the two protocols' log paths ought to be the same shape — a reader comparing an H1 and an H2 line for the same session is the case this issue is about, so I lean toward (2), but (1) shipped alone would already be a real improvement and is trivially reviewable.
Asked for
Decide between (1) and (2), implement it, and test it. Each behaviour wants a test seen red before the fix lands — revert, show it failing, restore, show it passing. The H2 side already has that discipline applied and its tests carry their own "To SEE THIS RED" instructions naming the exact substitution; follow that pattern rather than inventing one.
The H2 equivalents to model on: socket.rs:1883, socket.rs:1705, h2.rs:11254, and h2.rs:11379 (which pins that the peer is read once per connection, not per expansion).
Not in scope
lib/src/protocol/pipe.rs:325 was checked and is already cache-first (session_address.or_else(...)). It is not a defect and should not be touched.
Every other socket_ref().peer_addr().ok() in the tree — https.rs:3559, https.rs:3563, h2.rs:11263, h2.rs:11295, socket.rs:1715, socket.rs:1805 — sits inside a #[cfg(test)] module and is deliberate red-proof scaffolding. Counted by reading each site's enclosing module, not by grep line count. Leave them alone.
Activity
FlorentinDUBOIS commentedon Sep 25, 2026
Correction to this issue's body, now applied.
It attributed the H2 hoist — moving
peer=out of a per-expansion call and into a connection-owned field — to #1501. That is wrong. #1501 isrefactor(mux-h2): render the peer address where Debug named the socket: aDebugfield swap plus anensure_tls_flushedde-duplication,h2.rs+26/-… , and it never toucheslog_context!.The hoist is
4eb51741, the first of eight commits in #1471,refactor(mux-h2): read the log prefix peer from a connection-owned snapshot. Verified in-tree: that commit is where both macros go fromto
and where the field and its seeding (
peer_address: socket.peer_addr(),) are introduced.The body's code anchors were unaffected and remain correct —
h2.rs:11379is4eb51741's own read-once-per-connection count test. Only the PR number in the "model on this" sentence was wrong, and that sentence is what a reader follows to find the precedent, so it mattered.A third live-lookup surface this issue does not name
Found while implementing it, and outside its scope as written:
lib/src/protocol/mux/mod.rs:64and:91— thelog_context!andlog_context_lite!macros renderpeer = $self.frontend.socket().peer_addr().ok(),, which resolves to mio's inherent method rather than toSocketHandler::peer_addr. Same defect class, two more production sites. A grep forsocket_ref().peer_addr()does not find them, which is why this issue's own survey missed them.lib/src/protocol/mux/h1.rs:168—ConnectionH1'sDebugstill renders.field("socket", &self.socket.socket_ref()), handing mio'sDebuga local address, a peer address and a file descriptor. This is exactly what refactor(mux-h2): render the peer address where Debug named the socket #1501 changed on the H2 side and did not carry to H1.Neither is fixed here. Both want their own changeset, and the first in particular deserves a decision about whether every
peer=slot inmux/should be required to go through the trait — at which point the question is worth asking as a rule rather than site by site.fix(mux-h1): render the cached session peer instead of a live getpeer…
FlorentinDUBOIS commentedon Sep 25, 2026
Closed by #1526, merged as
6d6640bf.Option (2), the per-connection snapshot, was taken rather than (1), and what decided it is a case this issue's framing missed: option (1) fixes the PROXY and cache-then-live paths, but leaves ENOTCONN conditional on a cache the direct-accept routes may not hold —
http.rsandhttps.rsboth seedconfigured_peerfrom a best-effortpeer_addr().ok()at accept, anOptionprecisely because that lookup can fail. A per-line trait call would still renderpeer=Noneafter a reset on those routes.The cost argument inverted too.
4eb51741's expense on the H2 side was decouplingConnectionH2fromFront— 113 of 140 touch points — and that decoupling does not exist here:ConnectionH1already ownssocket: Front, and the four otherConnectionH1 { … }sites are destructuring patterns with... Production change: 2 macro lines, 1 field, 2 seeding lines, no signature changes.Three red-then-green recipes, each applied and the red observed. The one worth keeping is the third: it applies the option (1) shape and leaves only the read-once-per-connection count test red at
left: 4, right: 1while the other four stay green — reproducing4eb51741's own documented negative result, and showing (2) is load-bearing rather than decorative.One gap stated rather than papered over: symptom 3's TLS variant is covered by composition with
front_rustls_peer_snapshot_is_the_session_peer_not_the_accepted_socket, not by a direct test, becauseConnectionH1<FrontRustls>needshttps.rs's fixtures while the H1 macros are file-local.Still open, from the correction comment above:
lib/src/protocol/mux/mod.rs:64and:91renderpeer = $self.frontend.socket().peer_addr().ok(), resolving to mio's inherent method rather than the trait — two production sites asocket_ref().peer_addr()grep cannot see. Andh1.rs'sDebugstill hands mio'sDebuga socket, which is what #1501 changed on the H2 side. Neither is fixed here; both want their own changeset.fix(mux): render the session peer in the MUX log envelope
fix(mux): render the session peer in the MUX log envelope (#1536)