feat(relay): end a drain once every session has left - #4186
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Relay::run no longer sleeps out the whole drain window. It returns as soon as every established session has left (the deadline force-closes the rest) and logs which bound ended the drain, with the number of sessions the deadline force-closed. /metrics gains moq_relay_draining_sessions. The relay's own outbound cluster sessions are not counted: nothing sends them a GOAWAY, and the peer sees them close when the process exits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
September 25, 2026 19:59
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Collaborator
Author
|
Landing on
(Written by Grok 4.7) |
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.
Completes the
drain-exitquest and removes the line's last child, sizing the README[M]. What remains on the line is its own end-to-end test.What changed
Relay::runno longer sleeps out the whole drain window plus a second. It returns once every established session has left. The drain deadline force-closes stragglers, so the window is still the upper bound. The exit log says which bound ended the drain:drain complete: every session left; exitingwithelapseddrain deadline force-closed sessions; exitingwithelapsedandforced(the count)drain deadline passed with sessions still open; exitingwithforcedandopen. This is the one-second backstop for a close that never completes and should not happen./metricsgains amoq_relay_draining_sessionsgauge: the sessions sent a GOAWAY that have not left yet.How it works:
shutdown::Observernow keeps a tally.supervise(QUIC on tokio and io_uring, plus iroh) and the WebSocket handler hold a guard for each established session.drain_sessionholds a draining guard, and that guard counts the session as forced if it is still open at its deadline. The driver arms its force-close after the GOAWAY goes out, so it never fires before that deadline and every force-close gets counted. The guard also covers the WebSocket path, where the drain future is dropped if the driver ends first. Drain deadlines now usetokio::time::Instant, so the unit tests run on paused time.Decisions (the user was unavailable, so I took the recommended options)
doc/bin/relay/config.md./metrics. The relay exits right after it force-closes the stragglers, so a scrape would almost never see such a counter move. The count goes in the exit log instead, and the gauge shows the drain's progress up to that point.Tests
a_drain_ends_once_every_session_leaves(rs/moq-relay/tests/shutdown_signal.rs): the drain window is 600s. A one-shot client leaves on its GOAWAY, and/metricsthen shows one session still draining while the relay keeps running. When that straggler drops,runreturns within 5s. Without this change the test times out.shutdown::testscovers the tally on paused time:drainedwaits for every session, and only a session still open at the deadline counts as forced.API and wire impact
internal::Internal::with_shutdown(shutdown::Observer). TheTally/serve/drainedadditions onshutdown::Observerarepub(crate).Relay::runreturns as soon as a drain empties. An embedder that relied on it blocking for the full window will now see it return early.moq_relay_draining_sessions.Checks:
just checkscoped to this branch. Main'smoq-ffimay not compile until #4157 merges; this PR does not touch it.(Written by Claude Opus 5.5)
🤖 Generated with Claude Code