Repository navigation
Description
Split out of #1337, which asked three questions about the H2 core's relationship to time. Q2 (how the core learns the time) and Q13 (the flood detector's clock) are answered and implemented. Q3 — who owns timers — is not, and it is the one that actually gates the deterministic H2 simulator.
The end state
The core stops owning TimeoutContainer handles and instead returns a next-deadline Option<Instant> that the embedder arms, with Mux's SessionState impl becoming the adapter. This is the shape lib/src/protocol/udp/manager.rs already uses: a poll_timeout() returning the next deadline plus an ArmTimer output the shell acts on.
Blast radius on the core side is small and exactly enumerable — six TimeoutContainer sites in lib/src/protocol/mux/h2.rs (the field, the constructor parameter, the constructor init, and three reset() calls). The Mux side carries fourteen, plus a forwarder in connection.rs and two in router.rs.
Why this is not commissioned yet
Two reasons, and the second is the one worth writing down.
It buys nothing without the socket split. ConnectionH2 owns socket: Front and touches it at 34 sites, fifteen of which are socket_wants_write() — and that one is a TLS-buffer question wearing a socket's clothes. A clock-and-timer refactor without the socket boundary (Q10, #1339) yields no simulator. The timer half is the smaller half. So this work should start only once there is an actual commitment to sim/tests/h2_simulation.rs with a named owner, and that commitment has to scope the socket split too.
The ordering is not negotiable, for a counter-intuitive reason. "Re-validate at the firing site" is necessary but not sufficient. Under a memoized reschedule() plus a timer wheel that can fire early, re-validation alone converts a spurious fire into a lost wakeup — the timer is consumed, the re-validation rejects it, and nothing re-arms.
That is not hypothetical. It is exactly the bug fixed in the UDP shell in #1354: UdpManager::reschedule only emitted ArmTimer when the next deadline differed from armed_deadline, and the fix was clearing armed_deadline on entry to handle_timeout — consume-then-reschedule.
Today's H2 path cannot have that bug, and this is the part that makes the ordering load-bearing rather than cautious. TimeoutContainer is duration-based with no memoization: TimeoutContainer::set (lib/src/timer.rs:120-129) unconditionally cancels and re-arms, and every StateResult::Continue exit from Mux::timeout re-arms. The hazard belongs to the proposed design, not to the current one. C2 is what introduces the memoization that makes C1's re-validation load-bearing — which is why C2 must not land without C1.
A corollary worth stating: there is no standalone bug fix hiding in Q3. That was the most plausible "actionable now" candidate across the whole fourteen-question decision set, and it does not pan out.
Order
- C1 — stored deadlines plus re-validation in
Mux::timeout. - C2 —
poll_timeout(), adapter-owned container, consume-then-reschedule, and the twodebug_asserts carried over from the UDP manager. Must not land without C1. - C3 — delete the six
h2.rscontainer sites. - C4 — the simulator.
Nothing in this series lands before the Q2/Q13 clock work, which is now on main.
One loose end, unverified
In the backend-token branch, backend.timeout_container().triggered() fires and is re-armed only when !should_close, while the shared tail can return Continue through delay_close_for_frontend_flush("timeout") with only the frontend container re-armed. Whether that backend can still be in router.backends with live work at that point has not been traced — it needs a focused read of Connection::end_stream and delay_close_for_frontend_flush, or an integration test that stalls a backend after a partial response.
If it holds it is a small independent fix deserving its own issue; if it does not, it deserves one comment saying why it cannot happen. Explicitly flagged as unverified rather than asserted.
Activity
FlorentinDUBOIS commentedon Sep 20, 2026
C1, C2 and C3 landed on
mainin95c5f379(PR #1369) on 2026-09-20. C4 remains, and this issue stays open for it.Mux::timeoutpoll_timeout(), adapter-owned container, consume-then-rescheduleh2.rscontainer sitessim/tests/h2_simulation.rsThree things this issue asserted turned out to be wrong, and the PR corrected them with measurements rather than argument:
"There is no standalone bug fix hiding in Q3" — there was.
duration_to_tickrounds to the nearest tick, so an entry armed forDis delivered fromD - tick/2onwards. Withtick_ms = 100the earliness is(D + 50) mod 100, i.e. [0, 99] ms. A 60 sfront_timeoutcould write a 408 and close a live session at 59.901 s.Mux::timeouttook every delivery at face value.C3 could not be its own commit. An intermediate tree where the adapter owns a container and the core still owns one either arms the wheel twice or not at all, so neither half builds-and-tests green alone. C3 is folded into C2. The ordering that this issue said was load-bearing — C1 standalone, before C2 — is kept.
The ordering constraint is now a test, not an argument. Mutating the tree to the C2-without-C1 shape reddens with
timer coherence for Token(0): armed=false but the core wants Some(Instant{..})— the lost wakeup, caught byMux::debug_assert_timer_coherencecarried over fromUdpManager::check_invariants.The loose end flagged as unverified cannot happen. The question was whether a backend can still be in
router.backendswith live work when the shared tail returnsContinuewith only the frontend container re-armed. It cannot:Mux::timeout's backend branch callsbackend.end_stream(..)unconditionally at the bottom of every iteration, outside the if/else chain. No separate issue is needed.What C4 still needs is the socket boundary this issue named as its real gate (Q10, #1339):
ConnectionH2ownssocket: Frontacross 34 sites, fifteen of themsocket_wants_write(). The timer half was the smaller half, exactly as written here.FlorentinDUBOIS commentedon Sep 21, 2026
C4 is unblocked (2026-09-21), and the timer boundary itself is already done
Measured against
origin/mainat7be659544163f0d780f8eb0666a25d992f5f8e23.The gate is lifted
This issue's previous comment ended: "What C4 still needs is the socket boundary this issue named as
its real gate (Q10, #1339)." Q10 is now answered — the core goes byte-in / byte-out, rustls moves to
an I/O shell, and
Endpoint::socket(token)leaves the trait. See#1339 (comment).
Worth recording here: the timer extraction went further than this issue's table says
The table above marks C1/C2/C3 as landed in
95c5f379(#1369). Reading the tree rather than thetable: commit
22601f73, "refactor(mux): give the H1/H2 corespoll_timeout()and the adapter thetimer", is reachable through that merge, and
grepfinds zerocrate::timerorTimeoutContainerreferences in eitherh2.rsorh1.rs— every remaining hit is inside a comment.ConnectionH2::poll_timeout,arm_timeout,clear_timeoutandset_timeout_durationexist today,and LIFECYCLE.md invariant 23 records the ownership split.
So the timer sub-machine is not merely "C1-C3 of a four-step plan". It is a completed sans-io
extraction: the core publishes an intent, the adapter owns the real resource. That shape is now the
template every other sub-machine copies.
It is also the strongest available evidence for the strategy chosen for the rest of the work. Timers
came out first and independently of flow control, stream-slot bookkeeping and HEADERS/CONTINUATION
reassembly, on a 10,407-line file, without a parallel rewrite. That is a demonstration rather than an
assumption.
What C4 actually is, revised
C4 was scoped here as "the simulator,
sim/tests/h2_simulation.rs". Two revisions, both from readingthe code rather than re-arguing the design.
moonpool is not the first thing to build. A moonpool
Workloadbuys a seeded RNG and a virtualclock, which pay off once there is a wide randomized action grammar to sweep. Before that exists, the
useful artefact is a directed scenario library — the three
zero.storagebugs of 2026-09-21(#1396, #1397, #1401) and their neighbours — driven by a plain synchronous harness. That can be built
against
mainas it stands today, and it is not throwaway: the scenario and assertion layer isuntouched as each sub-machine is extracted, and only the driver is swapped, once per sub-machine.
The simulator alone is not sufficient, because both sides would be
sozu-lib. The plan is adifferential layer — one scenario replayed against the core in simulation and against a real worker
end-to-end — but
sim-observed == e2e-observedis not a real check here: in simulation we driveConnectionH2, and end-to-end we drive a worker that containsConnectionH2. A shared bug agreeswith itself, and that comparison would have been green through all three of the September 21 bugs.
The symmetry is broken by an independent oracle carried on the scenario, derived from the
scenario's own construction inputs and never from any Sōzu output. The assertion is three-way,
sim == e2e == expect. This is not novel here:sim/tests/tcp_preread_sim.rsalready carriesexpected: Option<Output>computed independently of the code under test, and the three regressiontests added on 2026-09-21 already encode a fixed header set with the peer's own
loona_hpack::Encoderand assert against that fixed set, never against what Sōzu claims it decoded.
One further trap specific to the end-to-end leg:
worker.soft_stop()crosses a real command channelto an independently scheduled thread, so replaying the #1401 scenario has three possible outcomes and
two of them pass without exercising the race at all. The harness therefore has to report a
race-window hit rate — confirming from captured logs that the drain was actually deferred — and treat
a scenario with zero hits as inconclusive, never as passing.
Where this sits in the sequence
Timer ownership is done. The remaining extraction runs: HPACK-owned state → connection-level flow
control → H2 wire-level stream-slot bookkeeping (then per-stream flow control) → the flood detector →
the GOAWAY/drain data split → HEADERS+CONTINUATION reassembly with the buffer-role split → the
write_streamsencoder-borrow restructuring → priority scheduling →ConnectionH2dropsFront.Two of those orderings are load-bearing rather than convenient. Reassembly cannot precede the
stream-slot map, because the CONTINUATION-flood abort path (CVE-2024-27316) calls
remove_dead_streammid-reassembly. And priority cannot precede the borrow restructuring for a borrow-checker reason:
H2BlockConverterholds&mut self.encoderacross the entire per-stream loop inwrite_streams, sono
&mut selfmethod can run inside it — the existing free functiondistribute_overheadwas madefree precisely to route around that.
Keeping this issue open for C4.
test(sim): deterministic H2-core simulation (#1359 C4)
test(sim): deterministic H2-core simulation (#1359 C4)
test(sim): deterministic H2-core simulation (#1359 C4) (#1485)
FlorentinDUBOIS commentedon Sep 24, 2026
C4 landed in #1485 (
3304bb1a). All four steps of this issue are now onmain, so closing.Mux::timeout95c5f379poll_timeout(), adapter-owned container, consume-then-rescheduleh2.rscontainer sitessim/tests/h2_simulation.rsThe timer boundary itself is verifiable rather than asserted: every remaining
crate::timer/TimeoutContainermention inh2.rsandh1.rsis a doc comment — 6 and 5 respectively, zero code.What C4 delivers
Byte-in/byte-out of
ConnectionH2as a server under a seeded action grammar, with read fragmentation down to one octet, partial writes down to one octet, and a 1% buggify wire truncation. Four properties, each seen red under a named production mutation: determinism (same seed identical, four seeds ≥2 distinct fingerprints so a constant trace cannot pass vacuously), theduration_to_tickearliness window probed at every millisecond of[0, 99], the concurrent-stream ceiling under adversarial interleaving, and per-stream credit attribution.Writing the determinism guard found a real clock leak:
ConnectionH2::newmakes the one wall-clockInstant::now()the core still performs, and the connection deadline inherited it — enough to flip a millisecond boundary against the harness's own clock. Re-armed throughConnection::set_timeout_durationat the injected base.Three production defects it found
fa0b93a4). The regression sweep found the failing band is wider than the simulator sampled:[1..=10, 13..=16, 25..=32].write_streamsarmed the frontend timeout on an ACK-only pass. Fixed in fix(mux-h2): arm the frontend deadline on stream bytes, not on an ACK-only pass #1494 (ad425e0b).What C4 does not cover, and why
The adapter half of the timer —
Mux::sync_timeout's re-validation, which is the actual C1 change — is not simulated.Mux::ready_innerandtimeout_innerreadInstant::now()andTimer::poll_tois private, so driving it fromsim/would be a host-clock read wearing a virtual clock's clothes. The core-side half is what C4's tick-boundary property adds; the adapter half remains covered bymux/mod.rs's own tests.Making it simulatable needs a
lib/change — injectnowintotimeout_inner/sync_timeoutand makeTimer::poll_toreachable. That is flagged rather than attempted, and is not part of this issue.Now that #1489 is fixed, the connection-level idle deadline assertion the simulator deliberately omitted — because asserting the old behaviour would have certified the gap — becomes available to
sim/.docs(mux-h2): say that the advertised connection-level receive window…
docs(mux-h2): say that the advertised connection-level receive window…