Repository navigation
fix(net): an unconfirmed close ends the session after a grace - #9399
Conversation
…st its deadline Past the drain deadline a session's supervision waits for its transport to confirm the close only for three round trips, at least 100ms, instead of until the idle timeout a gone peer's unacknowledged close capsule holds it to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A session this side closed ends once its transport confirms the close, or after three round trips and at least 100ms without it. A WebTransport close to a peer that is gone otherwise waits for the capsule's ACK until the idle timeout, and every caller awaiting Session::closed after an abort waited with it, such as a relay's drain past its deadline. The relay-side bound is dropped in favour of this one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Design change: the bound moved from moq-relay's (Written by Claude Opus 5.5) |
A close the protocol sends goes straight to the boxed transport, bypassing Supervisor::close, so start the grace from the shared Closing record instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
ℹ️ No correctness issues. One doc gap: three comments still describe the old end condition.
Approach: sound. Bounding the wait in Supervisor, where every close passes through, covers the relay drain, moq_tokio::Connection::drain, and close_by with one change. The transport's own close is left alone, so a live peer still gets the code.
Reviewed changes
I read all four files at 726cdb6 and checked how Closing::is_sent is set, how the driver re-polls the supervisor, and where moq-tokio sends its close capsule.
Supervisorclose grace: onceClosing::is_sent()is true,poll_endedstarts a timer of max(3·RTT, 100ms), andSession::closedresolves when the transport confirms or the timer runs out, still with this side'sClosing::cause.- Protocol closes start the timer the same turn: lite's
endand IETF'scloseboth run asprotocol.pollreturnsReady, anddriver.rsthen polls the supervisor again (closed = true), so the timer's wakeup gets registered. A close executed inpoll_runningis caught by the secondpoll_endedcall. - The close keeps going after the session ends: moq-tokio's
close_with_capsuleruns in a spawned task, so it keeps waiting for the ACK andclose_waits_for_capsule_ackstill holds. - Tests: a new mock knob,
withhold_close_confirmation, covers both the handle-abort and protocol-violation cases. Aquic_simtest covers a relay with a zero drain window and a peer whose packets are all lost.
ℹ️ Docs still say Session::closed waits for the transport
The new end condition isn't reflected in the docs. A caller reading them would assume closed() still means the transport confirmed the close.
Technical details
# Stale docs on when the session ends
## Affected sites
- rs/moq-net/src/session.rs:390-404 — public `Session::closed` doc: "Block until the transport session is closed" and "When the transport reports that this side closed it, this is this side's reason". It should also cover a close this side sent that goes unconfirmed past max(3·RTT, 100ms).
- rs/moq-net/src/session.rs:656 — `Supervisor` doc: "Finishes once the transport reports closed; everything else is moot then."
- rs/moq-net/src/driver.rs:61-67 — `State::supervisor` comment: "It finishes once the transport reports closed".
## Required outcome
- All three say the session also ends when the grace runs out on a close this side sent, and that the transport keeps delivering the close in the background.claude-opus-5-5 | 𝕏
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed the three stale docs from the Pullfrog review in 0e0d590: (Written by Claude Opus 5.5) |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since 726cdb6, a docs-only commit.
- Updated docs for the grace:
Session::closed, theSupervisordoc, and theState::supervisorcomment indriver.rsnow say the session also ends when a close this side sent goes unconfirmed past its grace. This resolves the prior doc feedback.
claude-sonnet-5-5 | 𝕏

Problem
A session this side aborts waits for its transport to confirm the close, and moq-tokio's WebTransport close deliberately waits for the CLOSE_WEBTRANSPORT_SESSION capsule to be acknowledged (
close_waits_for_capsule_ack). A peer that is gone (killed, unplugged, its browser closed) never acknowledges it, soSession::closedholds until the QUIC idle timeout. Every caller that aborts and then awaits the close waits with it: a relay's drain past its deadline (supervise,Observer::drain), dialed cluster links (moq_tokio::Connection::drain), andclose_by's predecessor closes. A relay with--drain-timeout 0stook 10s to exit after a WebTransport peer vanished.Approach
Supervisor, which publishesSession::closed, starts a grace once this side has sent a close: three round trips, at least 100ms. The trigger is the sharedClosingrecord that the boxed transport writes on every close, whether a handle, lite's driver, or IETF's terminal close sent it. The session ends when the transport confirms the close or the grace runs out, whichever comes first, and keeps this side's reason as before.close_waits_for_capsule_ackholds. The io_uring backend already caps its own capsule close at 1s.GoawayTimeoutcode in the capsule.main:session_close::an_unconfirmed_close_still_ends_the_session: a mock transport (newwithhold_close_confirmationknob) that never confirms this side's close, closed once by a handle's abort and once by the protocol over a peer's second SETUP stream. Both cases fail onmainwith "the unconfirmed close never ended the session".quic_sim::a_drain_waits_on_no_vanished_peer: a relay with a zero drain window over the real tokio WebTransport stack on kio's simulator, its peer's datagrams all lost after connecting, the listener closing after the drain asRelay::run's does. Fails onmainwith "the drain waited on the vanished peer: Elapsed".Impact
Session::closedafter any close this side sends (a handle's, or the protocol's over a peer's violation) resolves within max(3 * RTT, 100ms) when the transport cannot confirm it, instead of at the idle timeout. A transport that confirms in time sees no change.Alternatives
superviseandObserver::drain): the first revision of this PR. The review found the same hang inmoq_tokio::Connection::drainfor dialed cluster links, andclose_byhas it too, so the bound moved to the one place every close goes through.http/3 closed: code=0 reason="server shutdown"instead ofgoaway timeout.close_waits_for_capsule_ackprotects, and would leave other transports unbounded.Validation
just cion 726cdb6: 11139 tests passed.session.rs, whose grace started only inSupervisor::close, and passes on 726cdb6.just rs test -p moq-net --features async,-p moq-relay --features test-support,-p moq-tokio: 4229, 514 and 604 passed.moq-relay --drain-timeout 0s, onemoq announcedWebTransport client, SIGKILL the client, SIGTERM the relay.mainexits 10.005s after SIGTERM (drain deadline force-closed sessions; exiting elapsed=10.002s forced=1); this branch exits in 0.204-0.240s over three runs.mainlogssession error err=goaway timeout4/4. This branch logs it 3/4; in the 4th the client handled the GOAWAY message first and exited on its own (received goaway uri_len=0,Error: connection closed), and the relay ended that session after one grace (elapsed=103.7ms).Caused by
supervise(found by person)Decisions
Taken without the maintainer, who is away:
Supervisor, not in each caller, so everySession::closedafter a local close is bounded.Follow-ups
None.
Models
Size: S
Implementer: Claude, claude-opus-5-5, unknown effort (arm A)
🤖 Generated with Claude Code
(Written by Claude Opus 5.5)
Review
Rewritten by
quest reviewafter each round.Head: 726cdb6
Base: origin/main at caa7630
Risk: medium,
A bug fix in shipped moq-net session code that ends sessions whose peer never confirms a close after a grace period, and a drain no longer waits on a vanished WebTransport peer; the public API and wire format are unchanged, so consumers and relays would see only earlier session teardown, and a revert fully undoes it.Classified: medium by Claude Code, claude-haiku-5-5, low effort, session
9e6b718c-2bb1-40e6-941f-248285da5f5dReviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a202fe-c045-7f30-95a8-d39ed0989a44, round 2Score: 10/10,
The shared close record now starts the grace period for protocol-initiated closes, resolving the prior finding without apparent regressions in the incremental diff.Rounds: 3; first round 1 (medium 1); findings 1 (medium 1): fixed 1, refuted 0, open 0
Findings: none
The last round's findings, at c7afcf6:
rs/moq-net/src/session.rs:914:Cover protocol-initiated closes in the close lifecycle;Supervisor::poll_ended now arms the grace period from Closing::is_sent(), which boxed::Session::abort records for both handle and protocol closes, and the regression test adds a duplicate-SETUP protocol-close case.