Repository navigation
release: IPC off the main loop and graceful SIGTERM shutdown (S-38, S-42, S-43) - #40
Merged
Merged
Conversation
The packaged unit starts with no auth. On the test device auth is now on through a device-local EnvironmentFile drop-in; this documents the procedure without any values. - DEPLOYMENT_CHECKLIST §7a: /etc/sandstar/auth.env (root, 0600) with SANDSTAR_AUTH_USER/PASS, optional SANDSTAR_AUTH_TOKEN and SANDSTAR_WS_ALLOWED_ORIGINS; auth.conf drop-in with EnvironmentFile; verification (open reads 200, unauthenticated writes and editor endpoints 401, log line, password not in systemctl show, editor login); how to turn it off. - HowToUses/03_WEB_EDITOR.md: logging in to a device with auth on. - OVERVIEW: packaged unit is open on a fresh install; per-device drop-in turns auth on; editor logs in since S-32b. No code change. Verified on the test device (2026-11-23): open reads 200; unauthenticated pointWrite, HEAD /live/sedonaState, /api/sox/tree and PUT /file 401; editor SCRAM login, tree loaded, cookie PUT /file 200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC
…s (R-28, S-42)
The main loop read and answered each IPC connection synchronously. The
5 s timeout applied per read call, and writes had none, so a client that
sent a byte every few seconds, or never read its reply, held the
current_thread loop: REST, /live, SOX, the watchdog kick and the
sd_notify watchdog stopped, and with WatchdogSec=10 systemd restarted
the service. A throwaway test on the old path: a 200 ms per-read timeout
was held for 1055 ms by one byte per 150 ms.
- ipc.rs: an accept task (100 ms backoff on error) and one task per
connection; at most 4 at once, a fifth gets Error("busy"). Reading the
frame and writing the reply have a 5 s total deadline each; queueing
the command and getting the engine reply share one 10 s deadline. On a
failure the client gets EngineResponse::Error. A partial length prefix
is an error. Logs name the command (no field values) and are limited
to one line per kind per 10 s with a suppressed count.
- main.rs: only the command reaches the loop, through a bounded channel
(4) and a oneshot; a command whose client already gave up is skipped
and logged; Shutdown waits at most 1 s for its reply to be written.
- dispatch.rs: handle_connection becomes run (command in, reply out).
- sandstar-ipc: MAX_FRAME_SIZE is pub (same value).
- sandstar-cli: 20 s read/write timeout, above the server deadlines.
Behaviour: wire protocol unchanged. A command that cannot reach the
engine within 10 s is now not run and the client is told so (before, it
got no reply and the command ran later). Four slow local clients can keep
the CLI busy for 5 s at a time; the service and REST are unaffected.
Tests: gates.sh fmt, clippy, test (28 suites, 2921 passed, 0 failed),
hal OK; 16 IPC unit tests (total vs per-read deadline, unread reply, full
queue, abandoned command, written ack, oversized/garbage/partial frames,
connection limit and permit release). E2E on Windows TCP IPC: 6 slow
clients, REST /health 24/24 within 6 ms, slow ones closed at 5.0 s, CLI
"busy" while full then OK, poll and shutdown answered. The unix path is
not compiled on this machine; Linux CI covers it.
docs: HARDCODED_LIMITS.md IPC rows updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC
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
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
Lock-step from
developtomasterfor a field deploy (device 1-6).e37cbe1): docs, turning REST auth on per device (R-1).6d53a89, PR fix(ipc): serve IPC connections off the main loop with total deadlines (R-28, S-42) #38): IPC connections served off thecurrent_threadmain loop with total deadlines; max 4 connections, busy reply; CLI 20 s timeout (R-28).b8de2d5,f8966ab, PR fix(server): run the graceful shutdown on SIGTERM (R-13, S-43) #39): SIGTERM runs the graceful shutdown; listener installed first;STOPPING=1, watchdog kick, exit after cleanup on a stuck poll; visible errors for magic close, socket and PID removal (R-13).Behaviour change
systemctl stop/restartruns the shutdown (up to 5 s poll wait plus SVM stop).Test plan
developpush CI:TestandBuild ARMgreen onf8966abbash tools/gates.shgreen on each step (2921 passed, 0 failed)masterPR CITest/api/abouthash, service active, 0 new ERROR,sandstar-cli status, a restart showingengine stopped … reason="SIGTERM"🤖 Generated with Claude Code
https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC