Skip to content

Command processes survive SIGINT when parent exits #5592

Closed

Description

@schickling

Summary

Processes started via @effect/platform's Command API remain alive after the parent Effect program receives SIGINT. When the wrapper exits, the child continues running (PPID=1) and keeps its TCP port bound. This happens on both Node and Bun with current @effect/platform-node releases.

Minimal Reproduction

Repo: https://github.com/schickling-repros/2025-09-effect-command-sigint-leak

Steps:

  1. pnpm install
  2. pnpm start
  3. Wait for [child] listening on http://127.0.0.1:48787 pid=…
  4. Press Ctrl+C
  5. lsof -nP -iTCP:48787 -sTCP:LISTEN

Actual output after SIGINT:

[child] listening on http://127.0.0.1:60091 pid=3231873
wrapper pid=3231753 pgid=?
Child process tree (pid=3231873):
    PID    PPID    PGID COMMAND
3231873       1 3231873 node child.mjs
Wrapper exited. Checking listeners...
COMMAND   PID    USER FD TYPE DEVICE SIZE/OFF NODE NAME
MainThrea 3231873 schickling 53u IPv6 … TCP *:60091 (LISTEN)

The wrapper (index.mjs) builds the command via Command.make("bash", "-lc", "setsid node child.mjs") and provides NodeContext, NodeFileSystem, and NodeCommandExecutor layers. The child enables SIGINT handling, but because the parent exits immediately, the child becomes an orphan and keeps serving traffic.

Expected

Child process should be terminated (or the process group cleaned up) when the parent program receives SIGINT.

Actual

The parent exits immediately; the detached child keeps running with PPID=1, leaving its port bound.

Additional Context

  • Reproduced on Bun 1.2.22 and Node 24.8.0 with [email protected], @effect/[email protected].
  • In a larger CLI we saw the same behaviour: Wrangler, Vite, and workerd processes all stayed alive after Ctrl+C (tmp/cfchat-process-leak/run-20250930-171635.log).
  • @effect/platform-node-shared/internal/commandExecutor runs commands with detached: true. The release handler only kills the group when the exit code is non-zero; signal exits (code === null, signal !== null) skip cleanup.

Proposal

Update the release handler to kill the process group when a command terminates because of a signal (e.g. code === null && signal !== null). That would ensure detached groups are cleaned up after SIGINT.

Activity

  1. schickling commented on Oct 1, 2025

    @schickling
    ContributorAuthor

    Turns out this was about bash swallowing sigint signals, which unfortunately happens to be the behavior of bash and we can do nothing about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions