Skip to content

fix(ipc): serve IPC connections off the main loop with total deadlines (R-28, S-42) - #38

Merged
TurkerMertkan merged 1 commit into
developfrom
s42-ipc-off-main-loop
Nov 24, 2026
Merged

TurkerMertkan merged 1 commit into
developfrom
s42-ipc-off-main-loop

Conversation

@TurkerMertkan

Copy link
Copy Markdown
Collaborator

Summary

  • IPC connections (sandstar-cli) were read and answered synchronously inside the current_thread main loop; the 5 s timeout was per read call and writes had none. A slow client or one that never read its reply stopped REST, /live, SOX and the watchdog notification; with WatchdogSec=10 systemd restarted the service (R-28).
  • Now: an accept task and one task per connection (max 4, a fifth gets Error("busy")), total deadlines for read (5 s), queue + engine reply (10 s) and write (5 s), EngineResponse::Error on failure paths, abandoned commands skipped and logged, rate-limited logs, Shutdown waits ≤ 1 s for its reply, CLI 20 s timeout.
  • Wire protocol unchanged.

Behaviour change

  • A command that cannot reach the engine within 10 s is not run and the client is told so (before: no reply, the command ran later).
  • Four slow local clients can keep the CLI busy for 5 s at a time; service and REST are unaffected.

Test plan

  • bash tools/gates.sh: fmt, clippy, test (2921 passed, 0 failed), hal
  • 16 IPC unit tests (total vs per-read deadline, unread reply, full queue, abandoned command, written ack, bad frames, connection limit)
  • 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, shutdown answered
  • Linux CI (unix socket path is not compiled on Windows)

Docs: docs/Progress/HARDCODED_LIMITS.md IPC rows.

🤖 Generated with Claude Code

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
@TurkerMertkan
TurkerMertkan merged commit 6d53a89 into develop Nov 24, 2026
2 checks passed
@TurkerMertkan
TurkerMertkan deleted the s42-ipc-off-main-loop branch November 24, 2026 10:50
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