Skip to content

process: pass existing file descriptors to a child, and expose its terminating signal #10842

In review

Description

@DivMode

Summary

Two capabilities that Node's child_process.spawn has and effect/process ChildProcess (4.1.5) cannot express. They block migrating some real launchers to Effect.

1. Pass an existing parent file descriptor to the child

Node accepts an existing descriptor in stdio (spawn(cmd, args, { stdio: ["ignore", logFd, logFd, lockFd] })). Use cases we have:

  • A server writing directly into a log file. Tests read that file right after a request and rely on the server's own synchronous writes. A Sink on stdout/stderr streams through the parent, so lines land later than the request that produced them.
  • Inherited lock descriptors. A launcher passes open, already-acquired lock files to its child through extra descriptors. additionalFds always creates new pipes, so the child cannot inherit them.

A possible shape: stdout/stderr/additionalFds entries accepting an existing descriptor (for example a branded FileDescriptor, or a scoped FileSystem.File) that is passed through unchanged.

2. Expose how the child terminated

The handle exposes exitCode. A wrapper that mirrors its child's termination as 128 + signal (the shell convention) needs the terminating signal, which Node reports through 'exit''s (code, signal). A possible shape: an exit Effect yielding { code } | { signal }.

Related: #10841, which ensures detached: false children are only ever signalled by their own pid.

Activity

  1. clean99 commented on Nov 22, 2026

    @clean99
    Contributor

    I'd like to implement the second half of this (how the child terminated), using the shape suggested above: handle.exit: Effect<{ code: ExitCode } | { signal: ChildProcess.Signal }, PlatformError>.

    The Node and native Deno backends already record the exit code or signal, and Bun shares the Node backend. handle.exitCode would keep failing with PlatformError on signal termination, as it does and is tested today.

    One choice needs a maintainer: a required exit member changes the handle contract for custom spawners and makeHandle callers. Would you take it as a required member, or prefer a shape that leaves ChildProcessHandle unchanged?

    Tests would cover zero and nonzero exits, signals, repeated observers, pipelines (last command's result), input-stream failure precedence and cleanup, on Node, Bun and native Deno. Passing existing descriptors (the first half) and the process-group change in #10846 stay out of scope.

    Drafted by an automated contribution pipeline that I build and operate (https://github.com/clean99/software-factory).

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