Skip to content

fix: run xs.stopping on SIGTERM and Windows console-close, not just ctrl-c - #150

Merged
cablehead merged 2 commits into
mainfrom
fix-serve-sigterm
Aug 7, 2026
Merged

fix: run xs.stopping on SIGTERM and Windows console-close, not just ctrl-c#150
cablehead merged 2 commits into
mainfrom
fix-serve-sigterm

Conversation

@cablehead

@cablehead cablehead commented Aug 6, 2026

Copy link
Copy Markdown
Owner

xs serve ran its xs.stopping shutdown only on ctrl-c (SIGINT). Stop the server any other way and it skipped that shutdown, leaving the service processor's child processes running after exit.

A new shutdown_signal() helper covers the ways a process actually gets asked to stop:

  • Unix: SIGTERM, which is what systemd and most supervisors send, now runs the same shutdown as ctrl-c.
  • Windows: there is no SIGTERM, so it also listens for ctrl_close (console window closed) and ctrl_shutdown (system shutdown or logoff).

For reviewers

On Windows, CTRL_CLOSE only reaches a process that owns a console, not a service stopped through SERVICE_CONTROL_STOP. So the Windows side is best-effort console coverage, not full service support; CI's windows-amd64 job compiles and runs it.

On Unix I sent a real SIGTERM to a running xs serve and confirmed the xs.stopping frame lands and the process exits cleanly, the same as ctrl-c. cargo test --lib (189 passed) and cargo clippy are clean.

…hutdown too

Windows has no SIGTERM. ctrl_close and ctrl_shutdown are the closest
analogs: asked to terminate, clean up first. Select across ctrl_c,
ctrl_close, and ctrl_shutdown so all three run the same shutdown path.
cablehead added a commit to cablehead/pai-sho that referenced this pull request Aug 6, 2026
The daemon raced only ctrl_c before; nothing ran on SIGTERM, which is
what launchd/brew services/systemd/pkill send. Race the CLI socket loop
against a shutdown_signal() that selects SIGINT and SIGTERM, so a
supervisor stops the daemon cleanly and the TUN fd closes on exit (the
kernel then removes the utun and its route). Modeled on cablehead/xs#150
and cablehead/http-nu#53.
@cablehead cablehead changed the title fix: run xs.stopping shutdown protocol on SIGTERM, not just SIGINT fix: run xs.stopping on SIGTERM and Windows console-close, not just ctrl-c Aug 7, 2026
@cablehead
cablehead merged commit 54ac74e into main Aug 7, 2026
25 of 35 checks passed
@cablehead
cablehead deleted the fix-serve-sigterm branch August 7, 2026 04:14
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