Skip to content

SIGTERM killing an invalid node:child_process spawn terminates main process #65052

Description

@vdata1

Tip

Rewritten by @avivkeller

Version

v24.19.0, v26.6.0

Platform

macOS Darwin

Subsystem

node:child_process

What steps will reproduce the bug?

Running .kill('SIGTERM') on an invalid child_process spawn results in the termination of the main Node.js process (the caller)

For instance, running require('child_process').spawn('whoami').kill('SIGTERM');.

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?

Node.js should abort killing since .pid will be 0.

Original Issue

Version

v24.18.0

Platform

macOS Darwin

Subsystem

No response

What steps will reproduce the bug?

Hi,

I would like to report a bug that happens only on macOS. When run the code snippet below, the main process gets terminated:

var {spawn} = require('child_process');

Array.prototype[Symbol.iterator] = function* () {};
var proc = spawn("ts-node", ["--version"]); //or any other non-OS native command, e.g., brew --version  
console.log("subprocess forked");
proc.kill('SIGTERM');
console.log("Killed Subprocess");

How often does it reproduce? Is there a required condition?

It's a permanent effect

What is the expected behavior? Why is that the expected behavior?

To kill the child process only

What do you see instead?

I get the following output:

subprocess forked
zsh: terminated  node test.js

Additional information

No response

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