You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows: kill spawned process trees at the run/exec layer (taskkill /T /F) instead of error-handler pidtree enumeration #37
PR pnpm/pnpm#12403 fixed a Windows hang where every failedpnpm command took 20–46 s to exit. The error handler (pnpm/src/errorHandler.ts) kills descendant processes on exit by enumerating them via pidtree, which on Windows shells out to wmic and, where wmic is removed, a PowerShell Get-CimInstance Win32_Process fallback — a process listing that takes tens of seconds on busy machines. That lookup is now bounded by a 500 ms timeout so it can no longer stall the exit.
Problem
The timeout cures the hang, but on modern Windows pidtree can't finish within 500 ms, so the descendant-kill is effectively skipped there. Orphaned grandchildren of lifecycle scripts (e.g. a detached process spawned by a run/exec script) are therefore not reliably cleaned up on Windows.
Proposed fix
Adopt the approach npm and the wider ecosystem use: kill the spawned child's process tree at the run/exec/lifecycle spawn layer with taskkill /F /T /PID <childPid> on Windows (npm's @npmcli/promise-spawn signal-manager does exactly this; tree-kill too). Because the child PID is known at the spawn site, this:
actually terminates the whole subtree on Windows, fast, with no full process-list enumeration;
targets the spawned child, not pnpm itself — so it doesn't force-kill pnpm or lose the exit code (the only error-handler-level alternative, taskkill /T /PID <ownPid>, would);
lets the error-handler pidtree enumeration be removed entirely.
Keep the existing process.kill behavior on POSIX.
This is a refactor: pnpm needs to track (or kill at the spawn site) the long-running children it spawns for run/exec/lifecycle scripts, rather than discovering them post-hoc via pidtree in a generic error handler.
Notes
pacquet already received the robust native equivalent — a Windows Job Object with KILL_ON_JOB_CLOSE (the Cargo/Bun mechanism) — in the same change. Node can't use Job Objects without a native addon, which is why the JS CLI needs the taskkill approach instead.
I’ll keep the scope to the TypeScript pnpm CLI described here: move Windows descendant cleanup from the generic error-handler pidtree enumeration to the known child process at the run/exec/lifecycle spawn layer, using taskkill /T /F /PID <childPid> on Windows while preserving the existing POSIX behavior.
I’ll first pin the current behavior with native Windows regression coverage, then remove the now-redundant error-handler pidtree path only once the spawn-layer cleanup is covered.
I’m stopping work on this task because the proposed implementation is already on current main.
Commit b46f96165 / pnpm/pnpm#12925 added spawn-layer child tracking in @pnpm/exec.lifecycle, uses taskkill.exe /pid <pid> /T /F for tracked Windows children, wires lifecycle and exec spawns into that tracker, and makes the Windows error handler call killTrackedProcessTrees() instead of pidtree enumeration.
The remaining pidtree path in errorHandler.ts is POSIX-only, where the task explicitly says to keep the existing process-kill behavior. So I don’t see a remaining Windows implementation here that would justify another PR.
Activity
fix: kill spawned process trees with taskkill on Windows error exits
chore(deps): update pnpm to v11.15.0 (#469)
fix(runtime): trata taskkill 128 como sucesso, evita fallback caro a toa
amishabenramani commentedon Sep 27, 2026
I'm working on this.
I’ll keep the scope to the TypeScript pnpm CLI described here: move Windows descendant cleanup from the generic error-handler pidtree enumeration to the known child process at the run/exec/lifecycle spawn layer, using
taskkill /T /F /PID <childPid>on Windows while preserving the existing POSIX behavior.I’ll first pin the current behavior with native Windows regression coverage, then remove the now-redundant error-handler pidtree path only once the spawn-layer cleanup is covered.
Written by an agent (ChatGPT, GPT-5.6 Sol).
amishabenramani commentedon Sep 27, 2026
I’m stopping work on this task because the proposed implementation is already on current
main.Commit
b46f96165/ pnpm/pnpm#12925 added spawn-layer child tracking in@pnpm/exec.lifecycle, usestaskkill.exe /pid <pid> /T /Ffor tracked Windows children, wires lifecycle and exec spawns into that tracker, and makes the Windows error handler callkillTrackedProcessTrees()instead of pidtree enumeration.The remaining
pidtreepath inerrorHandler.tsis POSIX-only, where the task explicitly says to keep the existing process-kill behavior. So I don’t see a remaining Windows implementation here that would justify another PR.Written by an agent (ChatGPT, GPT-5.6 Sol).
zkochan commentedon Nov 8, 2026
pnpm/pnpm#12925 moved the Windows process-tree kill to the spawn layer with
taskkill /T /F, as proposed here.Written by an agent (Claude Code, claude-opus-5-5).