Repository navigation
fix(server): stop everything on Ctrl+C or a closed terminal - #585
Merged
Merged
Conversation
Ctrl+C on clopen or bun run dev returned the prompt while processes were still running, so starting again picked other ports; closing a terminal tab left what ran in it (a dev server) running for good. Under bun run, one Ctrl+C reaches the dev runner twice, 1 ms apart: from the terminal and forwarded by the runner. The supervisor took the copy as a second press and SIGKILLed every child, and bun run, on its own second SIGINT, killed the supervisor and returned the prompt with the children orphaned in their own process groups. The supervisor also ignored SIGHUP, and the server never stopped its terminal sessions or tunnels on shutdown. The duplicate is now absorbed exactly (the parent is a bun runner in the same process group), the first press stops gracefully and a second one forces. A stop is over only once the child and every process it started - collected first, since some sit in other groups - have exited; only a hang past the timeout is killed. SIGHUP stops everything when started from a terminal and is ignored without one (nohup, services). A supervised child stops itself if its supervisor disappears; Vite runs under a small guard for that. The server ends terminal sessions and awaits its tunnels on shutdown, and a requested stop exits 0. Needs PtyKit 0.1.1 (a closed tab ends its shell and everything started from it) and TunnelKit 0.1.0 (stopping waits for cloudflared to exit).
3 of 4 tasks
ArgaFairuz
added a commit
that referenced
this pull request
Nov 18, 2026
Unit tests failed on CI for every push since #585, and a diff test failed now and then before that. The launcher test failed every time on CI and never locally. stopOnSignals asked ps three times whether its parent was a bun runner before it installed any signal handler. Until a handler exists a signal takes its default action, so SIGHUP or SIGINT in that window killed the supervisor outright and left the server running with nothing to restart it. A slower runner made the window wider than the server's start-up, which is when the test sends SIGHUP. The handlers are now installed first and ps runs last; a signal that arrives meanwhile waits for its handler. With ps slowed by 300 ms the test failed every run before the change and passes after. The diff invariant test diffed a fully reversed 20,000-line file, Myers' worst case. That took 3 to 5 s against bun's 5 s timeout, so it passed or failed with the runner's load. The case keeps its shape at 4,000 lines; the invariant does not depend on size, and the diff runs in a worker in the app. The git identity test read the developer's own name when run from a shell Clopen started: GIT_CONFIG_COUNT/KEY_n/VALUE_n outrank every config file. The test now drops them.
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
Make Ctrl+C and closing a terminal stop Clopen completely before the prompt returns, with the ports free.
Why
Under
bun run, one Ctrl+C reached the supervisor twice and was treated as a forced stop;bun runthen killed the supervisor and orphaned the children with their ports. SIGHUP was ignored, and shutdown never ended terminal sessions or tunnels.Changes
Notes
Requires PtyKit 0.1.1 and TunnelKit 0.0.16 to be published, then
bun installto updatebun.lock.