Skip to content

subprocess.kill(0) terminates the subprocess on Windows since v23.4.0 #57669

Closed
@ehmicky

Description

@ehmicky

Version

v23.4.0

Platform

Windows

Subsystem

node:child_process

What steps will reproduce the bug?

import {spawn} from 'node:child_process';

const subprocess = spawn('node', ['--version']);
subprocess.kill(0);
subprocess.on('exit', (exitCode, signalCode) => {
	console.log({exitCode, signalCode});
});

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

Windows-only. Since Node 23.4.0.

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

Before Node 23.4.0, the subprocess is not terminated on any platform.

{ exitCode: 0, signalCode: null }

What do you see instead?

Since Node 23.4.0, the subprocess is terminated immediately on Windows:

{ exitCode: null, signalCode: 'SIGKILL' }

On non-Windows platforms, the behavior has not changed.

Additional information

This was introduced by the following PR: #55514 and issue: #42923

libuv handles sending 0 as a special case for Windows, so it works as intended on that platform, and there should not be a reason to convert it to SIGKILL instead.

0 is described under the following documentation:

0 can be sent to test for the existence of a process, it has no effect if the process exists, but will throw an error if the process does not exist.
Windows does not support signals so has no equivalent to termination by signal, but Node.js offers some emulation with process.kill(), and subprocess.kill():
Sending signal 0 can be used as a platform independent way to test for the existence of a process.

It seems like this PR forgot that special case.

ChildProcess.prototype.kill = function(sig) {
const signal = sig === 0 ? sig :
convertToValidSignal(sig === undefined ? 'SIGTERM' : sig);
if (this._handle) {
const err = this._handle.kill(signal);

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