Repository navigation
fix: bound descendant-process lookup on error exit to avoid a Windows hang - #12403
Conversation
Code Review by Qodo
1. Timeout may leak children
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe CI workflow gains a dedicated Windows smoke job (Node 22.13.0) and a separate ChangesWindows CI smoke job and timing diagnostics
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoTest: default pnpm e2e installs to trust lockfile to unblock Windows CI WalkthroughsDescription• Default e2e execPnpm environment to pnpm_config_trust_lockfile=true to skip verifier • Opt specific verifier-focused suites back in by omitting the new env default • Prevent Windows CI timeouts caused by per-package registry round trips during installs Diagramgraph TD
T["E2E suites"] --> E["execPnpm createEnv"] --> I["Spawned pnpm install"] --> V{"Verifier runs?"}
V -- "trustLockfile=true (default)" --> S["Skip verifier"]
V -- "omitEnvDefaults" --> R["Run verifier"] --> M["Registry mock"]
High-Level AssessmentThe following are alternative approaches to this PR: 1. Lower pnpm network concurrency for e2e runs
2. Disable verifier via a dedicated test-only CLI/config flag
3. Increase Windows test timeouts
Recommendation: Keep the PR’s approach: defaulting e2e installs to File ChangesTests (2)
Other (1)
|
0adceaa to
6c2e2b2
Compare
|
Code review by qodo was updated up to the latest commit 6c2e2b2 |
6c2e2b2 to
cb9f3d4
Compare
|
Code review by qodo was updated up to the latest commit cb9f3d4 |
cb9f3d4 to
cebb342
Compare
|
Code review by qodo was updated up to the latest commit cebb342 |
cebb342 to
1524665
Compare
|
Code review by qodo was updated up to the latest commit 7f6a6c3 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/test.yml:
- Around line 151-154: The run command at lines 151-154 executes the pnpm-only
test on all platforms instead of Windows only, which reduces test coverage on
Linux and macOS. Add a platform-specific condition (using runner.os) to the step
containing this run command to restrict its execution to Windows only, so that
non-Windows platforms continue executing the full affected-packages test sweep
via ${TEST_SCRIPT}.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d90ac5c6-07d0-447a-9890-283db57b7eb6
📒 Files selected for processing (3)
.github/workflows/ci.yml.github/workflows/test.ymlpnpm/test/utils/execPnpm.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- pnpm/test/utils/execPnpm.ts
- .github/workflows/ci.yml
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: windows-latest / Node.js 22.13.0 / Test
|
Code review by qodo was updated up to the latest commit aaf5f44 |
|
Code review by qodo was updated up to the latest commit deab5e4 |
|
Code review by qodo was updated up to the latest commit a1f0def |
|
Code review by qodo was updated up to the latest commit a9deac7 |
|
Code review by qodo was updated up to the latest commit ceafc36 |
|
Code review by qodo was updated up to the latest commit 4df8144 |
… hang On every error exit the error handler enumerates descendant processes via pidtree to terminate them. On Windows pidtree shells out to wmic and, where wmic is removed, a PowerShell Get-CimInstance fallback that can take 20-46s on busy machines, so any failed pnpm command hung that long before exiting (and the verifyDepsBeforeRun e2e suites, full of intentional failures, blew past the 70-minute CI cap). Race the lookup against a 2s timeout so process.exit is no longer stalled by it. Also split the CI pnpr-binary cache into restore + an explicit save step so a failing test step no longer discards the Rust build.
4df8144 to
4ce3f8b
Compare
|
Code review by qodo was updated up to the latest commit 4ce3f8b |
The lookup is instant on POSIX (one ps), so the bound only ever clips the pathologically slow Windows path; 500ms keeps margin for a loaded machine while cutting the worst-case error-exit delay.
|
Code review by qodo was updated up to the latest commit a2aebd9 |
Micro-Benchmark ResultsLinux |
…Object pnpm's error handler kills descendant processes on exit; pacquet had no equivalent, so a lifecycle script's detached grandchild could outlive a failed or interrupted install. Mirror Cargo and Bun: assign the pacquet process to a Job Object with KILL_ON_JOB_CLOSE so the OS tears down the whole tree when pacquet exits — the robust mechanism on Windows, which has no process groups. Best-effort (silently skips if the job can't be created or assigned) and a no-op on Unix, where the kernel's process-group and signal model already covers it. This deliberately diverges from pnpm's pidtree mechanism: pnpm is Node and has no Job Object binding, whereas pacquet is native and can use the better primitive. Implemented with raw windows-sys FFI (already in the dependency tree), so no new crates are added.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12403 +/- ##
=======================================
Coverage 88.14% 88.14%
=======================================
Files 300 301 +1
Lines 39730 39734 +4
=======================================
+ Hits 35020 35024 +4
Misses 4710 4710 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
a2aebd9 to
889cfc6
Compare
|
Code review by qodo was updated up to the latest commit 889cfc6 |
|
@coderabbitai approve |
✅ Action performedComments resolved. Approval is disabled; enable |
On an error exit the error handler terminated descendant processes by enumerating them with pidtree, which on Windows shells out to wmic (or a PowerShell fallback) and regularly exceeds the 500 ms budget introduced in pnpm#12403 - so the cleanup was effectively skipped there and children spawned by still-running commands were orphaned. Track the PIDs of the child processes spawned for pnpm exec and pnpm dlx in a registry in `@pnpm/exec.lifecycle`. On Windows the error handler now kills the process tree of every still-running tracked child with taskkill /T /F - the PID is already known, so no process-list enumeration is needed. taskkill failures (exit code 128 when the tree root already exited) are ignored. On POSIX the existing enumeration is kept: one ps call is fast there and also reaches the descendants of children that pnpm cannot track. Lifecycle scripts (pnpm run and install hooks) are spawned inside `@pnpm/npm-lifecycle`, which does not expose the spawned child process, so they cannot be registered from this repository yet. Wiring them up needs a small change in pnpm/npm-lifecycle (exposing the child PID and an on-spawn callback); the tracker in `@pnpm/exec.lifecycle` is written so runLifecycleHook can reuse it once that lands. Fixes https://github.com/pnpm/pnpm/issues/12406
Problem
On Windows, any failed
pnpmcommand hangs 20–46 seconds before exiting. The error handler (pnpm/src/errorHandler.ts) enumerates descendant processes viapidtreeto terminate them on every error exit. On Windowspidtreeshells out towmicand, where wmic has been removed, a PowerShellGet-CimInstance Win32_Processfallback — a process listing that takes tens of seconds on busy CI runners.This also broke Windows CI: the
verifyDepsBeforeRun/*e2e suites are full of intentional-failure assertions (e.g.pnpm startwith--config.verify-deps-before-run=errorwhen deps aren't installed). Each failure paid the ~23 s error-handler tax, so the suite blew past the 70-minute cap.pnpm installand success paths never hit the error handler, which is why only failures were slow.Diagnosed by sampling
process.getActiveResourcesInfo()during the hang: it showed a lingeringProcessWrap(a spawned child), and hookingchild_process.spawnnamed it (wmic→powershell … Get-CimInstance Win32_Process, exiting after ~23–46 s).Fix
Race the descendant-process lookup against a 2 s timeout. If it doesn't return in time, skip the kill and exit —
exit()callsprocess.exit, which abandons the still-running (harmless, read-only) process query instead of blocking on it. The fast path (Unix, fast Windows) is unchanged.Confirmed on Windows CI: the failing
startinvocations dropped from ~23 s to ~2.7 s, andmultiProjectWorkspace.tswent from 716 s to 124 s.Also included
The CI pnpr-binary cache is split into
restore+ an explicitsavestep that runs right after the build, so a failing test step no longer discards the ~20-minute Rust build (the combinedactions/cacheonly saved in a post-job step that gets skipped on failure).Changeset:
pnpmpatch.Written by an agent (Claude Code, claude-opus-4-8).