Files
node/test/fixtures/child-process-kill-spawn-error.js
Lazizbek Ergashev ce20f7acb3 src: don't kill own process group on failed spawn
libuv only assigns a pid to the process handle once uv_spawn() has
succeeded, so a child that never started keeps pid 0. Calling kill()
on such a child still reached uv_process_kill(), which ended up in
kill(0, signal) and signalled every process in the caller's own
process group, Node included.

Return ESRCH when the handle has no pid, and zero the pid in the
constructor so the check never reads an unassigned value.

Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65054
Fixes: https://github.com/nodejs/node/issues/65052
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-09-12 10:43:37 +00:00

5 lines
175 B
JavaScript

const { spawn } = require('child_process');
const child = spawn('foo123');
child.on('error', () => {});
if (child.kill() !== false || child.killed !== false) process.exit(1);