mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
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>
17 lines
645 B
JavaScript
17 lines
645 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const assert = require('assert');
|
|
const { spawn } = require('child_process');
|
|
|
|
// Killing a child process that never spawned must not signal the process
|
|
// group of the caller. The check runs in a detached child so that a
|
|
// regression cannot take the test runner down with it.
|
|
const childPath = fixtures.path('child-process-kill-spawn-error.js');
|
|
const child = spawn(process.execPath, [childPath], { detached: true });
|
|
|
|
child.on('exit', common.mustCall((code, signal) => {
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(code, 0);
|
|
}));
|