Repository navigation
fix(server): run the graceful shutdown on SIGTERM (R-13, S-43) - #39
Merged
Merged
Conversation
The server only listened for SIGINT. systemctl stop/restart and the deploy scripts send SIGTERM, so the process died at once: no poll wait, no SVM stop, no HAL shutdown, no /dev/watchdog magic close, no IPC socket or PID file cleanup, and the last log lines could be lost. - signal.rs: TermSignal (SIGTERM on Unix, never fires elsewhere). A closed signal stream is logged and no longer reported as a signal (also for SIGHUP). - main.rs: the SIGTERM listener is installed first, before the PID file, /dev/watchdog and the IPC socket exist; a SIGTERM during startup stays pending and the first loop turn shuts down. select! gets a SIGTERM branch; "engine stopped" carries reason=SIGTERM/SIGINT/IPC command. Shutdown sends STOPPING=1 and kicks both watchdogs after the poll wait. If the poll does not come back in 5 s, the HAL shutdown skip is logged and the process exits after cleanup, because dropping the tokio runtime would wait for the stuck blocking task until systemd's SIGKILL. - watchdog.rs: a failed magic close is a warning, not "closed". - ipc.rs: socket cleanup warns on errors other than NotFound. - pid.rs: a failed PID file removal goes to the log, not only stderr. Behaviour: every stop/restart now runs the shutdown (up to 5 s poll wait plus SVM stop), so a restart can take a few seconds longer. If the kernel watchdog is enabled (R-42, off in the field), stopping the service no longer resets the board. Unit file unchanged. Tests: gates.sh fmt, clippy, test (29 suites, 2921 passed, 0 failed), hal, docs OK. tests/sigterm.rs (Unix only, first run on Linux CI): the real binary gets SIGTERM after startup and during startup; exit 0, "engine stopped" with SIGTERM, PID file and socket removed. Both fail on the old code (death by signal). docs: DEPLOYMENT_CHECKLIST.md section 7 stop log lines; .claude/rules/engine-async.md shutdown note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC
Linux CI failed both SIGTERM tests: they captured only stderr, but without --log-file the tracing logs go to stdout (tracing_subscriber::fmt defaults to io::stdout, tracing-subscriber 0.3.22 fmt/mod.rs:232), so "engine running" and "engine stopped" never showed up. The startup test already saw exit 0. The tests now read stdout and stderr into one list. No behavior change. The logging.rs comment "stderr only" for this branch is wrong; left as is (systemd captures both, the unit uses --log-file). Tests: Unix only, not compiled on Windows; Linux CI is the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC
2 of 4 tasks
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.
Summary
systemctl stop/restartand deploys send SIGTERM, so the process died without its shutdown (poll wait, SVM stop, HAL shutdown,/dev/watchdogmagic close, socket/PID cleanup, log flush) (R-13).main(a SIGTERM during startup stays pending), newselect!branch,engine stoppednames the signal.STOPPING=1, watchdog kick after the poll wait, exit after cleanup if the poll is stuck (tokio runtime drop would wait forever), visible errors for magic close, socket and PID file removal, no false signal on a closed stream.Behaviour change
Test plan
bash tools/gates.sh: fmt, clippy, test (2921 passed, 0 failed), hal, docstests/sigterm.rs(SIGTERM after and during startup; exit 0,engine stoppedwith SIGTERM, PID file and socket removed). Unix only, not compiled on Windows.Docs:
DEPLOYMENT_CHECKLIST.md§7,.claude/rules/engine-async.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC