Repository navigation
fix(cli): install the shutdown signal handlers before serving - #9073
Conversation
`drive` spawned `shutdown_signal()` as a task, and tokio installs a
signal's handler on that future's first poll. A listener could bind and
log before the task ran, so a SIGTERM sent right after took the default
action and killed the process. `stdin_shutdown` hit this under load
("CLI exited with signal: 15 (SIGTERM)").
`shutdown_signal` now installs both handlers when called, and
`run_stages` calls it before anything binds. `main` fixed the same race
in #5575 with a larger rework; this is the release-line minimum.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
ℹ️ One minor suggestion inline: the new comment claims more scope than the change covers.
Approach: sound. The fix rests on the real difference between tokio::signal::unix::signal, which installs the OS handler when it is called, and tokio::signal::ctrl_c, which is an async fn and therefore installs on first poll. Creating the future in run_stages before spawn_moq closes the window that let a SIGTERM sent right after "listening" kill the process. Spawning it there rather than globally is also the right call: moq play only catches SIGINT, so installing a SIGTERM handler on that path would make playback unkillable by a supervisor.
Reviewed changes
- Handlers installed eagerly:
shutdown_signalis now a sync fn that creates the SIGTERM and SIGINTSignals (Ctrl-C on Windows) and returns the future that waits on them, so registration happens at construction. This is the whole behavioral fix. - Spawned before any stage binds:
run_stagesspawns that future into itsJoinSetahead ofspawn_moq, anddrivedrops its own spawn.drive's only other callers are the unit tests, so no path loses the handler. - Regression test:
a_signal_before_the_first_poll_is_caughtbuilds the future, sends the process a SIGTERM, then awaits it under a timeout. With lazy registration the test binary is killed by the signal, so it fails for the right reason.
deepseek-v4.1-flash | 𝕏
… bind Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Comment scoped accurately:
run_stagesnow says the handlers precede "the stage listeners" rather than "anything binds", which matches that--iroh-enabledbinds its endpoint inNetearlier. This is the only change since the prior review, and it addresses the earlier inline suggestion; that thread is resolved.
(Written by DeepSeek V4.1 Flash)
deepseek-v4.1-flash | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Nothing new since the prior approval:
ffbf34d21is still the head, so the only delta relative to the last review is the comment scope fix it already covered.run_stagessays the handlers precede "the stage listeners", which is accurate given that--iroh-enabledbinds its endpoint inNetearlier, and the single prior inline thread is resolved. - Fix still verified in source:
shutdown_signal()installs the SIGTERM and SIGINTSignals when called and returns the waiting future, andrun_stagesspawns it beforespawn_moqbinds any stage listener.driveholds only the join loop, andmoq playkeeps its own SIGINT-only handling.
(Written by DeepSeek V4.1 Flash)
deepseek-v4.1-flash | 𝕏

On
release, the CLI can die from a SIGTERM sent right after its listener comes up.drivespawnsshutdown_signal()as a task, and tokio installs a signal's handler only when that future is first polled. A listener can bind and log "listening" before the task runs, so a SIGTERM in that window takes the default action and kills the process instead of shutting it down.rs/moq-cli/tests/stdin_shutdown.rshits this under load:One re-run passed. It failed inside a Nix build of
moq-cli, which runs the test suite, so onreleasethe flake also fails any build that rebuilds the CLI.mainfixed the same race in #5575 ("catch shutdown signals before serving") as part of a larger signal rework. This is the release-line minimum.Changes
rs/moq-cli/src/main.rs:shutdown_signalis now a plain function. It installs the SIGINT and SIGTERM handlers (Ctrl-C on Windows) when called and returns the future that waits on them.run_stagesspawns it beforespawn_moqbinds the stage listeners, anddriveno longer spawns it.a_signal_before_the_first_poll_is_caught: it makes the future, sends the process a SIGTERM before polling it, and expects the future to see the signal.Validation
releasebehaviour), the test binary is killed by the SIGTERM (exit 143).sh/rs/select.sh checkandsh/rs/select.sh testover this diff: clean, 257 tests pass.Impact
moq playis unchanged; it has its own Ctrl-C handling.Caused by
#4287 (close the relay connection on SIGINT and SIGTERM) spawned the handler as a task in
drive.mainreplaced that in #5575, which was never backported.Models
Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort
(Written by Claude Opus 5.5)
🤖 Generated with Claude Code
Review
Rewritten by
quest reviewafter each round.Head: ffbf34d
Base: origin/release at 2ab31a1
Risk: medium,
the base has no RISK.md to name what is always high or customer-facing, so every change is mediumClassified: medium by default
Reviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a1ed01-887e-7f63-8360-cbab5579df41, round 2Score: 9/10,
The only change since the last review clarifies a comment accurately and introduces no actionable defects; builds and tests were not run as instructed.Rounds: 2; first round 0; findings 0: fixed 0, refuted 0, open 0
Findings: none
Reviewer: Codex, gpt-6.1-sol, low effort, shadow
Session:
01a1ed01-887e-77d0-96f3-ff6b12c7943fRounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0