fix: run xs.stopping on SIGTERM and Windows console-close, not just ctrl-c - #150
Merged
Conversation
…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.
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.
xs serveran itsxs.stoppingshutdown 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:ctrl_close(console window closed) andctrl_shutdown(system shutdown or logoff).For reviewers
On Windows,
CTRL_CLOSEonly reaches a process that owns a console, not a service stopped throughSERVICE_CONTROL_STOP. So the Windows side is best-effort console coverage, not full service support; CI'swindows-amd64job compiles and runs it.On Unix I sent a real SIGTERM to a running
xs serveand confirmed thexs.stoppingframe lands and the process exits cleanly, the same as ctrl-c.cargo test --lib(189 passed) andcargo clippyare clean.