Skip to content

fix(net): an unconfirmed close ends the session after a grace - #9399

Merged
kixelated merged 4 commits into
mainfrom
fix/relay-drain-deadline-close
Nov 22, 2026
Merged

kixelated merged 4 commits into
mainfrom
fix/relay-drain-deadline-close

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

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, so Session::closed holds 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), and close_by's predecessor closes. A relay with --drain-timeout 0s took 10s to exit after a WebTransport peer vanished.

Approach

  • moq-net's session Supervisor, which publishes Session::closed, starts a grace once this side has sent a close: three round trips, at least 100ms. The trigger is the shared Closing record 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.
  • The transport keeps delivering the close on its own afterwards: moq-tokio's capsule task still waits for the ACK, so close_waits_for_capsule_ack holds. The io_uring backend already caps its own capsule close at 1s.
  • A live peer acknowledges within the grace, so it still gets the GoawayTimeout code in the capsule.
  • Tests at both layers, each failing on main:
    • session_close::an_unconfirmed_close_still_ends_the_session: a mock transport (new withhold_close_confirmation knob) 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 on main with "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 as Relay::run's does. Fails on main with "the drain waited on the vanished peer: Elapsed".

Impact

  • Public API: none.
  • Wire: none.
  • Behavior: Session::closed after 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

  • Bound only the relay's waits (supervise and Observer::drain): the first revision of this PR. The review found the same hang in moq_tokio::Connection::drain for dialed cluster links, and close_by has it too, so the bound moved to the one place every close goes through.
  • Close every QUIC connection at the drain deadline: rejected, it races the abort and erases the close code for live peers. Measured: a live client saw http/3 closed: code=0 reason="server shutdown" instead of goaway timeout.
  • Bound moq-tokio's capsule ACK wait: rejected, it would undo the stalled-socket guarantee close_waits_for_capsule_ack protects, and would leave other transports unbounded.

Validation

  • just ci on 726cdb6: 11139 tests passed.
  • The protocol case fails with c7afcf6's session.rs, whose grace started only in Supervisor::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.
  • Real binaries: moq-relay --drain-timeout 0s, one moq announced WebTransport client, SIGKILL the client, SIGTERM the relay. main exits 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.
  • Same, with the client left alive, 4 runs on each: main logs session error err=goaway timeout 4/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

Decisions

Taken without the maintainer, who is away:

  • The bound lives in moq-net's Supervisor, not in each caller, so every Session::closed after a local close is bounded.
  • The grace is max(3 * RTT, 100ms), the same wait moq-tokio's WebTransport teardown gives a peer to close after the capsule, rather than a new number.

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 review after 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-248285da5f5d

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a202fe-c045-7f30-95a8-d39ed0989a44, round 2

  • Score: 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:

    • Fixed: medium, 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.

kixelated and others added 2 commits November 22, 2026 02:55
…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>
@kixelated kixelated changed the title fix(relay): a vanished WebTransport peer no longer holds the drain past its deadline fix(net): an unconfirmed close ends the session after a grace Nov 22, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Design change: the bound moved from moq-relay's supervise and Observer::drain into moq-net's session Supervisor, which every local close goes through. Review round 1 found the same unbounded wait in moq_tokio::Connection::drain for dialed cluster links, and close_by has it too, so bounding each caller would leave the class open. The relay changes are reverted; the relay's quic_sim test stays as the end-to-end regression.

(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>
@kixelated
kixelated marked this pull request as ready for review November 22, 2026 11:37
@kixelated
kixelated enabled auto-merge November 22, 2026 11:38
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ecf3e050-a7d9-4bc7-93cf-a3420b2f2ab5
Commits

Reviewing files that changed from the base of the PR and between 142769f and 0e0d590.

Files selected for processing: 5

  • rs/moq-net/src/driver.rs
  • rs/moq-net/src/session.rs
  • rs/moq-net/tests/integration/session_close.rs
  • rs/moq-net/tests/integration/support/mock.rs
  • rs/moq-relay/tests/integration/quic_sim.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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.

  • Supervisor close grace: once Closing::is_sent() is true, poll_ended starts a timer of max(3·RTT, 100ms), and Session::closed resolves when the transport confirms or the timer runs out, still with this side's Closing::cause.
  • Protocol closes start the timer the same turn: lite's end and IETF's close both run as protocol.poll returns Ready, and driver.rs then polls the supervisor again (closed = true), so the timer's wakeup gets registered. A close executed in poll_running is caught by the second poll_ended call.
  • The close keeps going after the session ends: moq-tokio's close_with_capsule runs in a spawned task, so it keeps waiting for the ACK and close_waits_for_capsule_ack still holds.
  • Tests: a new mock knob, withhold_close_confirmation, covers both the handle-abort and protocol-violation cases. A quic_sim test 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.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Fixed the three stale docs from the Pullfrog review in 0e0d590: Session::closed, Supervisor, and State::supervisor now say a close this side sent also ends the session once its grace runs out unconfirmed.

(Written by Claude Opus 5.5)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the delta since 726cdb6, a docs-only commit.

  • Updated docs for the grace: Session::closed, the Supervisor doc, and the State::supervisor comment in driver.rs now say the session also ends when a close this side sent goes unconfirmed past its grace. This resolves the prior doc feedback.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit a376c84 Nov 22, 2026
5 checks passed
@kixelated
kixelated deleted the fix/relay-drain-deadline-close branch November 22, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant