Gracefully shut down child processes on quit#119
Open
gwleuverink wants to merge 6 commits into
Open
Conversation
if set skips tree-kill on app-quit so supervisors get a chance to spin down child processes
run pint & prettier locally. upstream rule defaults changed.
Collaborator
Author
|
I will update the docs once you've had a look at this |
SRWieZ
approved these changes
Jun 2, 2026
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.
Add a
handlesOwnShutdownoption for child processes and wait for graceful shutdown on quitAn app can spawn child processes that manage their own long-running children (queue workers, subprocesses, PTYs). Some of those know how to shut their children down cleanly: signal each one, let it flush or persist state, then exit. The current quit path stops them two ways:
stopProcesstree-kills. It sends SIGTERM to the whole tree (killSync(pid, 'SIGTERM', true)), so a process's children die out from under it before it can wind them down in order.Quit doesn't wait.
before-quitruns synchronously and quits on the same tick it issues the kills, so even a process that traps SIGTERM has no time to finish cleanup.What changed
A
handlesOwnShutdownoption onChildProcess(start/php/node/artisan). When set, stopping the process sends a single SIGTERM to that process alone instead of tree-killing its descendants, so it can bring its own children down on its own terms.Important
The flagged process must trap SIGTERM and stop its children itself. If it doesn't, the default SIGTERM action still terminates it and leaves the children orphaned. That's why it's opt-in and defaults to
false(the existing tree-kill, no handler needed), and why the name is what it is: it should be obvious at the call site who's responsible. On Windows, where signals can't be trapped, it falls back to tree-kill so children are never orphaned.This needs to be documented clearly.
A graceful app quit.
before-quitno longer quits immediately. It now:handlesOwnShutdown;app.quit(), capped at 12s so a stuck process can't block the quit. Apps with no child processes quit immediately.Notes
handlesOwnShutdownonly when it's explicitly set, so existingassert*callbacks keep working without a major version bump (inline note on simplifying this in the next major).dist/is left out for CI to build.handlesOwnShutdownreaching the child-process API for each spawn method (and defaulting tofalse), plus a fake assertion.