Skip to content

release: IPC off the main loop and graceful SIGTERM shutdown (S-38, S-42, S-43) - #40

Merged
TurkerMertkan merged 4 commits into
masterfrom
develop
Nov 24, 2026
Merged

TurkerMertkan merged 4 commits into
masterfrom
develop

Conversation

@TurkerMertkan

Copy link
Copy Markdown
Collaborator

Summary

Lock-step from develop to master for a field deploy (device 1-6).

Behaviour change

  • IPC: a command that cannot reach the engine within 10 s is not run and the client is told so; a fifth concurrent IPC client gets "busy".
  • Every systemctl stop/restart runs the shutdown (up to 5 s poll wait plus SVM stop).
  • Wire protocols, routes, auth and the unit file are unchanged.

Test plan

  • develop push CI: Test and Build ARM green on f8966ab
  • bash tools/gates.sh green on each step (2921 passed, 0 failed)
  • master PR CI Test
  • Device 1-6 after deploy: /api/about hash, service active, 0 new ERROR, sandstar-cli status, a restart showing engine stopped … reason="SIGTERM"

🤖 Generated with Claude Code

https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC

TurkerMertkan and others added 4 commits November 23, 2026 17:56
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
@TurkerMertkan
TurkerMertkan merged commit 3c2ef58 into master Nov 24, 2026
4 checks passed
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