fix: forward SIGINT to child process for proper Ctrl+C handling#32
Merged
fix: forward SIGINT to child process for proper Ctrl+C handling#32
Conversation
When running shell commands, the spawned child process is in a separate process group (due to detached: true). This causes Ctrl+C to not properly terminate the child. Forward SIGINT signals to the child's process group.
The previous approach (forwarding SIGINT to child's process group via -pid) didn't work because deep descendants like vite create their own process groups. Now recursively walks the process tree and sends SIGINT to every descendant individually.
Pipe stdout/stderr (instead of inherit) so we can unpipe before killing the child tree. This suppresses pnpm's "ELIFECYCLE Command failed." message that appears when its child exits non-zero during shutdown.
…ss groups - Use stdio: 'inherit' to preserve colors, escape codes, and terminal clearing - On Ctrl+C, only SIGTERM descendants in different process groups (e.g. vite) while leaving the PM's group (pnpm/bun) untouched - This lets bun handle SIGINT naturally (prints "Shutting down", kills vite, exits 0) and pnpm sees a clean exit (no ELIFECYCLE) - Effect.uninterruptible prevents the runtime from racing to kill children
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
@effect/platform'sCommandExecutor(which usesdetached: true) and spawn child processes directly via Node'schild_process.spawnWhy tree-kill instead of process group forwarding
The initial approach (
process.kill(-pid, 'SIGINT')) only reaches processes in the child's immediate process group. In practice, deep descendants like vite create their own process groups (observed: pnpm/bun in PGID X, vite in PGID Y), so they never receive the forwarded signal. Tree-kill (pgrep -Precursion) finds and signals every descendant regardless of process group.Test plan
pm devin a project with vite — Ctrl+C — no orphaned processes (lsof -i :3000clean)pm iwith Ctrl+C during install — clean exitpm run <script>with other long-running scripts