src: don't kill own process group on failed spawn · nodejs/node@7011764 · GitHub
Skip to content

Commit 7011764

Browse files
lazergaduh95
authored andcommitted
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: #65054 Fixes: #65052 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent 54d7743 commit 7011764

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎src/process_wrap.cc‎

Lines changed: 5 additions & 1 deletion
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const { spawn } = require('child_process');
2+
const child = spawn('foo123');
3+
child.on('error', () => {});
4+
if (child.kill() !== false || child.killed !== false) process.exit(1);
Lines changed: 16 additions & 0 deletions

0 commit comments

Comments
 (0)