src: don't kill own process group on failed spawn - #65054
Open
lazerg wants to merge 3 commits into
Open
Conversation
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>
lazerg
force-pushed
the
fix/issue-65052-kill-unspawned-process
branch
from
August 5, 2026 16:51
1c77865 to
38627f1
Compare
avivkeller
reviewed
Aug 5, 2026
avivkeller
reviewed
Aug 5, 2026
avivkeller
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
libuv only assigns a pid to the process handle once
uv_spawn()succeeds, so a child that never started keeps pid 0. Callingkill()on that child still reacheduv_process_kill(), which ended up inkill(0, signal)and signalled every process in the caller's own process group, Node included. The handle is now reported asESRCHwhen there is no pid, sochild.kill()just returns false. The pid is also zeroed in the constructor so the check never reads an unassigned value.Reproducing it on its own needs no prototype tampering:
In the report the spawn failed for a different reason: overriding
Array.prototype[Symbol.iterator]makesnormalizeSpawnArguments()build an empty env, so the command was no longer found through PATH. The dead handle is what took the parent down.Behavior change
kill()on a child that failed to spawn used to returntrueon POSIX. It now returnsfalse.Windows was never affected by the process-group problem, since
uv_process_kill()bails out withEINVALwhen the handle has no process handle. It reached thethrow new ErrnoException(err, 'kill')branch instead, so therekill()goes from throwingEINVALto returningfalse. Both platforms now agree.subprocess.killedis also left alone in this case, which matches what the docs already say about it being set only when a signal is sent successfully.Fixes: #65052