Repository navigation
Description
Part of the H2 sans-io extraction decision set. lib/src/protocol/mux/ holds 95 I/O and
ambient-state touchpoints: 26 mechanical, 55 structural, 14 requiring a maintainer decision
(h2.rs 53 / mod.rs 24 / connection.rs 9 / stream.rs 6 / router.rs 3). ConnectionH2<Front: SocketHandler>
carries 54 production socket references in h2.rs alone, and Context<L> holds
pub pool: Weak<RefCell<Pool>>. The structural majority is the signal: this is not a mechanical
extraction.
No design is proposed here and no work is budgeted until the question below is answered. The goal of
the extraction is a deterministic simulator for H2 in the FoundationDB style described in
doc/testing.md; every question below is a place where the current code reaches for I/O, the clock,
the allocator or a random source from inside what would become the pure core.
Question 10 — does the core still know what a socket is
h2.rs:1685 ConnectionH2<Front: SocketHandler>. Stay generic, with the simulator supplying an
in-memory implementation — cheapest, and keeps socket_wants_write / socket_close TLS-and-fd
semantics inside the core's contract — or drop the parameter for byte-in / byte-out entry points?
Dropping it first requires deciding how rustls's socket_wants_write(), consulted at 15 sites, is
represented. That is the crux: socket_wants_write is not a socket question, it is "the TLS layer has
buffered handshake or alert bytes it must flush before progress". A byte-in/byte-out core needs that
as an explicit output, not an ambient query.
Question 11 — round-trip times
h2.rs:3866 snapshot_rtts. Are client_rtt / server_rtt
- (a) passed in as already-captured
Option<Duration>, or - (b) kept as in-core
getsockopt(TCP_INFO)?
(a) lets Endpoint::socket(token) (mod.rs:289) be deleted from the trait outright; (b) keeps it,
and keeps a syscall inside the core.
Why these are one decision
11 is only a real question once 10 is settled. If the core stays generic over SocketHandler, (b)
remains available and Endpoint::socket survives. If the core goes byte-in/byte-out, (a) is forced
and Endpoint::socket must go. Answering 11 first would pre-commit 10 by accident.
Activity
FlorentinDUBOIS commentedon Sep 21, 2026
2026-09-21: Q10/Q11 stand as posed, but two of this issue's numbers are wrong, three citations have drifted, and a real correctness bug was hiding in the boundary it flags
Corrections
"54 production socket references in
h2.rsalone" is wrong — it is 34, and it was 34 before thisissue was opened. Counting
self.socketoccurrences above themod tests {line gives 34 againstorigin/main(42ac35bf) and 34 against74c3ba1f, the commit immediately preceding this issue's2026-09-18 opening. So the figure was never correct on any commit — it is not a stale count.
Issue #1359 independently re-derived it as "34 sites" when naming this issue as its gate; that
number is the right one.
"
socket_wants_write(), consulted at 15 sites" is correct.grep -nreturns 16 hits, of whichone (
h2.rs:2056) is a doc comment and 15 are call sites, unchanged since before this issue opened.All three line citations have drifted. They were exactly right when written; five commits since,
most recently #1396 (+520 lines), have shifted them:
74c3ba1f42ac35bfh2.rs:1685—struct ConnectionH2<Front: SocketHandler>h2.rs:1712h2.rs:3866—fn snapshot_rttsh2.rs:4174mod.rs:289—fn socketonEndpointmod.rs:346The 95-touchpoint breakdown (26 mechanical / 55 structural / 14 decision;
h2.rs53,mod.rs24,connection.rs9,stream.rs6,router.rs3) is arithmetically self-consistent — both groupingssum to 95 — but is not independently re-derivable, because the issue does not state the rule that
sorts a touchpoint into one bucket or another. No evidence it is wrong; only that it cannot be
checked the way the other two were.
What Q10 and Q11 reduce to
Q10 is unchanged in substance. The fork is still "stay generic over
SocketHandler" vs."byte-in/byte-out", and
socket_wants_write()— the TLS-flush query, not a plain read or write — isstill the crux at 15 call sites. Only the scale moves: the generic-
Frontsurface inh2.rsproduction code is 34
self.socketaccesses plus oneEndpoint::socket(token)call fromsnapshot_rtts. Smaller than claimed, not smaller in kind.Q11 is unchanged and still gated on Q10: pass
Option<Duration>in (which letsEndpoint::socket, nowmod.rs:346, be deleted) or keepgetsockopt(TCP_INFO)in-core (whichkeeps it).
The standalone defect, found and fixed
ConnectionH2::zerois simultaneously the read-side accumulation buffer for a HEADERS+CONTINUATIONfield block in progress —
header_block_fragmentis a(start, len)window into it, valid acrosshowever many
readable()passes the block takes, by protocol design — and the write scratch spaceflush_pending_control_framesreuses for any queued WINDOW_UPDATE or RST_STREAM, on anystream.
Mux::readydispatches frontendreadable()thenwritable()in the same sweep, soordinary connection-level flow-control housekeeping landing between a stream's HEADERS and its
CONTINUATION cleared
zero.storageout from under the accumulating fragment.No attacker is needed. The failure is silent: the clobbered bytes still HPACK-decode, so a
legitimate two-frame block carrying
x-sozu-marker: legitimate-valuecame back as("from", <garbage>)rather than as a decode error.Fixed in #1397 by
header_block_reassembly_in_progress()(h2.rs:3887), gating the WINDOW_UPDATEdrain (
h2.rs:3950) and RST_STREAM drain (h2.rs:4021) offlush_pending_control_frames(
h2.rs:3899) to defer rather than flush. Nothing is lost — both frame kinds already armWRITABLEat queue time. This mirrors the protection the codebase already applies to the same buffer in the
other direction: a stalled zero-buffer write already disables READABLE so a fresh read cannot
clobber it; the read side had no equivalent.
Same bug class, different trigger — not fixed
graceful_goaway(h2.rs:5011) also clearsself.zero.storageunconditionally ath2.rs:5029toserialize the advisory GOAWAY, despite its own comment stating the intent to keep reading in-flight
streams during the drain window. A worker's graceful shutdown or hot reload landing mid-reassembly
hits the identical corruption — unconditionally, every time, not only when a control frame happens
to be queued. It wants its own changeset and its own test.
FlorentinDUBOIS commentedon Sep 21, 2026
Q10 and Q11 are answered (2026-09-21). Also: four of this issue's five per-file counts are wrong.
Measured against
origin/mainat7be659544163f0d780f8eb0666a25d992f5f8e23.Q10 — the core goes byte-in / byte-out
ConnectionH2loses itsFront: SocketHandlerparameter. It never touches a socket,Readiness, ormio. rustls lives entirely in an I/O shell.
The argument that decided it is not the fifteen
socket_wants_write()sites. It is the backendleg:
Hard-coded to
SessionTcpStreamwhatever the frontend is —MuxClearorMuxTls. AndSessionTcpStreamoverrides neithersocket_wants_writenorsocket_close, so it takes the traitdefaults (
false/ no-op,lib/src/socket.rs). The same generic core is therefore alreadymonomorphised a second time today, with every one of those fifteen checks resolving statically to
false. Sōzu demonstrates on every request that the TLS coupling is incidental rather thanstructural. That is stronger evidence than any argument about the call sites themselves.
Two supporting findings:
The fifteen sites do not survive as core logic. About eleven are
trace!/debug!arguments oredge-triggered WRITABLE re-arming (
ensure_tls_flushed, theflush_pending_control_framesstages).The remaining four gate a close, and that need is satisfied by inverting control: the core emits its
bytes plus a close intent, and the shell — which alone knows the rustls backlog — decides when to
tear down. None of the fifteen decodes a frame, advances a stream, or touches flow control.
Counting
h1.rs(10) andshared.rs'sdrain_tls_close_notify(2), the mechanism is 27 sitesrepo-wide, every one asking the same question, and entirely inert for plain TCP.
The alternative this issue posed — "stay generic, simulator supplies an in-memory implementation" —
is what we already do.
SocketHandleris the TLS abstraction trait andsocket_wants_write()is the ambient poll. Keeping it renames the problem. Worth noting because
quinn-protois oftencited as the model here: it does put TLS inside the core behind
crypto::Session, but for a reasonthat does not transfer — QUIC carries the TLS handshake inside its own CRYPTO frames, so its core has
no choice. H2 runs on an ordinary TLS record stream that we already terminate.
One more blocker worth recording, since it is what actually stops an in-memory implementation today:
SocketHandler::socket_ref/socket_mutreturn&mio::net::TcpStream, a concrete OS type. Noin-memory pipe can satisfy that signature. The current H2 unit-test harness uses a real loopback TCP
socket accordingly, so it is not deterministic in the FoundationDB sense either.
Q11 — forced by Q10, exactly as this issue predicted
Option (a).
client_rtt/server_rttarrive as already-capturedOption<Duration>, andEndpoint::socket(token)leaves the trait. This issue's own framing was right: "If the core goesbyte-in/byte-out, (a) is forced and
Endpoint::socketmust go."socket_rttis a rawgetsockopt(TCP_INFO)(lib/src/socket.rs), reached throughEndpoint::socket(token)from four call sites —snapshot_rttsinh2.rsplus three inline copiesof the same three-line pattern in
h1.rs, which has no shared helper. RTT is intrinsically alive-socket property; a byte-in/byte-out core cannot produce it, so the shell injects it. Note this
changes the
Endpointtrait's shape for every implementor, not only H2.Correction to this issue's counts
Four of the five per-file figures are wrong, and the issue contradicts itself: its breakdown sums
53+24+9+6+3 = 95 while it quotes "54 production
socketreferences inh2.rs" separately.7be65954h2.rsmod.rsconnection.rsrouter.rsstream.rsMethod: non-comment lines matching
socket, restricted to each file's production range (before its#[cfg(test)]/mod tests). It is textual, so it also catches field declarations and the localsocket_write: bool; the point is that it is the same method applied to every file.Two deltas matter.
stream.rsis 0, not 6.Streamtouches no socket at all — the file says so itself: "Streamdoes not own a socket reference — the frontend socket lives on the parent
Mux/connection and thebackend socket lives on…". The six were comments. This is good news for sequencing: the stream slot
lifecycle can be extracted without untangling any I/O.
router.rsis 12, not 3, and they are the least mechanical ones in the tree:set_nodelay(
setsockopt),register_socket(epoll registration, with its own CWE-400 rollback comment), and theraw
TcpStreamhandoff from the connect path. These stay in the shell, but there are four times asmany of them as this issue budgeted.
Related measurements, same revision: nine live
Instant::now()/SystemTime::now()reads remain inmux/, all at construction or in diagnostics — the per-pass snapshot discipline from #1358 holds.Exactly one production ULID site, in
ConnectionH2::create_stream, which hides aSystemTime::now()inside
rusty_ulidand is therefore invisible to any grep overmux/. Both pool checkout sites arealready
Option-fallible with a graceful REFUSED_STREAM-shaped fallback, which is the shape asans-io core wants.
The hardest site, recorded so it is not discovered late
ConnectionH2::writable, GoAway arm (h2.rsaround:4145): a nested check that fuses "rustls hasbuffered records" with "did the kernel accept the flush". Its own comment calls it the primary
truncation vector under HAProxy chaining. A sans-io core cannot attempt a flush itself, so this
two-level backpressure signal has to be reconstructed entirely from what the shell reports back.
Getting it wrong is data loss, not style.
What this unblocks
#1359's C4 was explicitly gated on this question. It is now unblocked.
The extraction is a strangler — one sub-machine at a time, each independently mergeable with its
regression test seen red first — with a differential layer replaying one scenario against both the
core in simulation and a real worker. Sequencing follows in its own comment.
refactor(mux-h2): reach TLS through three named seams
refactor(mux-h2): reach TLS through three named seams (#1499)
refactor(mux-h2): render the peer address where Debug named the socket
refactor(mux-h2): render the peer address where Debug named the socket
refactor(mux-h2): render the peer address where Debug named the socket
refactor(mux-h2): render the peer address where Debug named the socket
refactor(mux-h2): render the peer address where Debug named the socket (
refactor(mux-h2): hand ensure_tls_flushed the TLS answer instead of a…
refactor(mux-h2): hand ensure_tls_flushed the TLS answer instead of a…
refactor(mux-h2): hand ensure_tls_flushed the TLS answer instead of a…
refactor(mux-h2): hand ensure_tls_flushed the TLS answer instead of a…
refactor(mux-h2): hand ensure_tls_flushed the TLS answer instead of a…
refactor(mux-h2): split finalize_write and flush_pending_control_fram…
refactor(mux-h2): split finalize_write and flush_pending_control_fram…
refactor(mux-h2): lift writable's close-arm flush triples into the so…
refactor(mux-h2): lift writable's close-arm flush triples into the so…
refactor(mux-h2): lift writable's close-arm flush triples into the so…
refactor(mux-h2): sample the frontend RTT once per Mux pass (#1339, Q11)
refactor(mux-h2): sample the frontend RTT once per Mux pass (#1339, Q…
refactor(mux-h2): drop ConnectionH2's Front parameter into an H2Shell (…
FlorentinDUBOIS commentedon Sep 25, 2026
Q10 and Q11 are shipped. Closing, with the numbers re-measured one last time.
Verified against
origin/mainatfa11f549c02722a378b983a0b3cb716187f54e14. Citing by symbolrather than by line, because every line citation in this issue's original text had drifted by the
time the first comment checked them — that is the whole lesson of #1447.
Q10 — the core went byte-in / byte-out, as decided
ConnectionH2no longer carries aFront: SocketHandlerparameter. It is a plainpub struct ConnectionH2. The socket,Readinessand rustls live inH2Shell<Front: SocketHandler>, whichowns the core rather than the other way round.
The measurement this issue opened on was "54 production
socketreferences inh2.rsalone". Alater comment corrected it to 34 and showed it had never been 54 on any commit. It is now 11,
and the more useful fact is where they are: every one of them sits inside an
impl<Front: SocketHandler> H2Shell<Front>block. The twelfth occurrence is prose — a doc commenton
ConnectionH2::peer_addressexplaining why thepeer=slot is no longer sourced fromself.socket. Zero socket references remain in the core.socket_wants_write()— the crux, and correctly identified as such — is no longer an ambient querythe core makes. It is the shell's business, which is what "byte-in/byte-out" had to mean for the
15 call sites to be answerable at all.
Q11 — (a), and
Endpoint::socketis gonesnapshot_rttsis nowfn snapshot_rtts<E: Endpoint>(&self, endpoint, linked_token) -> (Option<Duration>, Option<Duration>), returningself.client_rttandendpoint.peer_rtt(token).No
getsockopt(TCP_INFO)inside the core.Endpoint::socketwas deleted from the trait, exactly as the issue predicted answering (a) wouldallow. Its replacement is
Endpoint::peer_rtt(token) -> Option<Duration>, and the distinction isthe point rather than a rename: the predecessor handed out a
mio::net::TcpStream, a concrete OStype, so any connection could reach any other connection's socket for any purpose and no in-memory
transport could ever satisfy the trait. The successor returns the value. The only surviving
mention of
fn socketonEndpointinmod.rsis that doc comment recording why it went.The standalone defect this issue flagged and left open is also closed
The 2026-09-21 comment recorded a second instance of the
zero.storageclobber —graceful_goawayclearing the buffer unconditionally to serialize the advisory GOAWAY, mid-reassembly, on every
graceful shutdown rather than only when a control frame happened to be queued — and said it wanted
its own changeset and its own test. It got both, as #1398, now closed.
graceful_goawaycomputesheader_block_reassembly_in_progress()and hands it toH2DrainState::begin_graceful_drain, which answersDeferInitial; the deferred GOAWAY isre-emitted by
flush_pending_control_framesthroughsend_initial_goawayonce reassemblycompletes, and
readiness.arm_writable()guarantees awritable()pass so it is not left waitingon an unrelated event. The test is
a_legitimate_continuation_survives_a_graceful_goaway, and itcarries a "To SEE THIS RED" recipe whose honest content is that no mutation is needed — the red was
the shipping behaviour on
main.What this issue does not close
Nothing here. The sans-io arc's remaining content lives in #1340 (Q12 part 2) and #1341 (Q4).
perf(mux): read TCP_INFO only when an access log needs it (#1598)