Repository navigation
fix(mux-h2): arm the frontend deadline on stream bytes, not on an ACK-only pass - #1494
Merged
Merged
Conversation
…te pass `ConnectionH2::poll_read_target` documents that PING, WINDOW_UPDATE and SETTINGS must not reset the frontend timeout, "otherwise a peer sending periodic PINGs prevents timeout detection on stuck sessions". The read path honoured it, arming only on DATA payload and on HEADERS. The write path undid it. `ConnectionH2::write_streams` armed the connection deadline as its first statement, and `writable()` dispatches into that function for every proxying state, so reaching it never meant application data was being written. A connection whose only queued output was the PING ACK or SETTINGS ACK that `flush_pending_control_frames` had just drained sits in `H2State::Header` like any other, falls through the preamble's `None`, and armed. Measured with `front_timeout` 600 s and one stream opened at 10 ms, a PING at 10 s, a SETTINGS at 40 s and a PING at 500 s each pushed the deadline a further full timeout out; WINDOW_UPDATE queues no acknowledgement, gave the write path no reason to run, and correctly did not move it. `front_timeout` therefore never fired on a PING-only peer. The arm moves to the `H2StreamId::Other` arm of `ConnectionH2::handle_write`, gated on `size > 0`. Both halves are load-bearing and neither is implied by reaching the write pass: the stream id is what makes the bytes a stream's rather than `self.zero`'s, and the size is what makes them bytes the socket actually took. `arm_timeout` reads the pass clock snapshot, so arming per transmit lands on the same instant pass entry would have computed - the gate is the whole change, not the moment. The call-site count stays at three, which is what LIFECYCLE §9 invariant 9 states. The per-stream idle deadline is a separate mechanism and is untouched. The close and drain paths keep their deadline the way every other pass does, by flushing a stream's bytes: `Mux::timeout` already re-arms explicitly on each branch that keeps a session alive, and `H2State::GoAway` / `H2State::Error` never reach the stream-write path. What ends is `Mux::drive_frontend_shutdown_io` forcing a write pass on every shutting-down poll and renewing a draining session for free, whether or not a byte moved. Four tests pin it, each pairing its negative with a positive leg on the same connection, because a build that never armed would satisfy every "the deadline did not move" assertion while turning `front_timeout` into an unconditional session cap. Refs #1489 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 03:45
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.
Refs #1489.
ConnectionH2::poll_read_targetdocuments, in prose, that PING, WINDOW_UPDATE and SETTINGS must not reset the frontend timeout — "otherwise a peer sending periodic PINGs prevents timeout detection on stuck sessions". The read path honoured it.write_streamsopened with an unconditionalarm_timeout(), so any pass with something to send reset it, including a pass whose only output is an acknowledgement.Reproduced before touching anything,
front_timeout600 s, one stream at 10 ms.t0 + 600.01 sis the correct answer — armed at 10 ms:The three that moved are exactly the three that queue an acknowledgement. WINDOW_UPDATE queues nothing, which is why it correctly never moved.
The harness had to wait on bytes actually reaching the connection socket via
peek; without that the loopback read quiesces on a "not yet"WouldBlockand the last two rows silently measure a frame that never arrived — which is how the first two reproduction attempts under-reported the defect.The rule, and where it lives
Arm the frontend deadline on application-stream activity in either direction. Inbound is unchanged (DATA payload, HEADERS). Outbound becomes: a write-pass transmit that moved a real stream's bytes.
The seam is the
H2StreamId::Otherarm ofConnectionH2::handle_write, gated onsize > 0, replacing the unconditional arm at the top ofwrite_streams.handle_writeis already where the pass classifies what it emitted — it decidesresume_bytesvsstream_bytesat that point — so the rule reads literally at the site rather than being reconstructed from context.self.zero's, andsize > 0separates bytes the socket took from an offer it refused.finalize_writewould have been wrong:resume_bytesdeliberately never reaches it, and threeDoneterminators bypass it entirely.arm_timeout()readsself.now, the snapshotwritable()adopts at pass entry, so arming per transmit computes the same instant pass entry would have. The gate is the whole change, not the moment.Production
arm_timeout()call sites stay at 3, which is what LIFECYCLE §9 invariant 9 asserts.A larger finding than the issue described
Close and drain paths were checked and need no special case — they keep their deadline the way every other pass does, by flushing a stream's bytes, and
Mux::timeout_inneralready re-arms explicitly on each branch that keeps a session alive.What does end is this:
Mux::drive_frontend_shutdown_iosetsforce_h2_writeunconditionally for an H2 frontend, so a draining connection still inH2State::Headerreachedwrite_streamson every shutting-down poll. Today's unconditional arm therefore made a draining session immune tofront_timeoutfor the entire drain — byte or no byte. That is now bounded bygraceful_shutdown_deadlineand byMux::timeout's own draining branch.Covered by
a_draining_write_pass_that_moves_stream_bytes_still_arms_the_deadline, which asserts both legs.The per-stream idle deadline is untouched.
Direction disclosure
handle_writeserves backend H2 too (Position::Client), so an upstream sending keepalive PINGs no longer renewsbackend_timeouteither — a stuck upstream that only pings now times out. Response HEADERS/DATA reads still renew it. The same rule applied consistently, e2e green, and LIFECYCLE invariant 22's prose updated to match.Two independent reverts, which is what rules out a vacuous pass
A test asserting only "the deadline did not move" passes against a build that never arms — the opposite defect, and worse, since it turns
front_timeoutinto an unconditional session cap. So each of the four tests pairs a negative leg with a positive leg on the same connection, and two different reverts redden them in two different places:Revert A —
self.arm_timeout();back at the top ofwrite_streams→1100 passed; 4 failed, each on its negative leg:Revert B —
if size > 0→if false, a build that never arms on the write path →1100 passed; 4 failed, all four on their positive legs:left: 600.01s(right 1130s),left: 600.01s(right 650s),left: 600s(right 620s) ×2.Test-shaping check: the production change is three lines. The only literal shared with test code is
0, inassert_eq!(written, 0, …)— a behavioural "the pass moved no byte" premise. Assertions readpoll_timeout()offsets,expect_writeandmetrics.bout.Documentation — the inconsistency was the bug
write_streams. Rewritten with why reachingwrite_streamsis not evidence of application data.mod.rs— both namedwrite_streamsas an arm site.h2.rs—poll_read_target's reset list, and thewritable()dispatch comment, which claimed "Reset the timeout here … so that control frame writes don't reset it": precisely the thing it failed to do.doc/h2_mux_internals.md—writable()dispatch andhandle_writesections.Verification
No test deleted or ignored, no assertion loosened, no
#[allow], no lint escape.Disclosed: 64 exempt citation spans, audited rather than accepted
--basereports 64 re-anchored spans exempt from the comparison and never checked at all — not 0. The line insertions inh2.rs/mod.rsdrifted 49 pre-existing citations that were intact at base.--showbuckets them exactly:doc/h2_mux_internals.md, independently covered by rule 4 (all 16 pinned blocks quote their cited lines verbatim).Two citations were removed rather than renumbered, so nothing remains to compare: LIFECYCLE §7.1's
h2.rs:5257/h2.rs:1835-1841became symbol citations, andh2_mux_internals.md'sh2.rs:4142becamecancel_timed_out_streamsplus the file — the script's own recommendation, since it had drifted onto a blank line. No newfile.rs:NNNcitation was added anywhere.Follow-up, not done
The H2 simulator (#1485) deliberately does not assert the connection-level idle deadline, because "asserting today's behaviour would certify the gap". The gap is now closed, so that assertion becomes available to
sim/.