Repository navigation
fix(wsl): tree-kill timed-out wsl.exe probes on the execFile path - #19341
marcdhansen wants to merge 1 commit into
Conversation
…anism) `src/main/wsl.ts` spawns `wsl.exe` via `execFile`/`execFileSync` with a `timeout`. That timeout kills only the direct child -- it does not walk the process tree -- so on Windows the console host and any Windows-side descendants survive. This is the same defect class fixed in stablyai#19319 for `runWslProcess`/`probeGuestEnvironment` (`terminationBarrier: true` on the `runProcess` path), but on a different mechanism: an `execFile`/`execFileSync` timeout rather than `runProcess`'s non-barrier `terminate()`. Async sites migrated to `runProcess` + `terminationBarrier: true` (feasible -- `runProcess` is async, and windowsHide comes free via `resolveSpawn`): - `wslUncDirectoryExistsAsync` - `execFileUtf8` (shared helper, extracted to wsl-exec-utf8.ts to keep wsl.ts under its 300-line budget), used by `listWslDistrosAsync`, `listRunningWslDistrosAsync`, `getWslHomeAsync` Sync sites (`wslUncDirectoryExists`, `listWslDistros`, `getWslHome`) stay on `execFileSync` and get a bounded, best-effort `taskkill /t /f` fallback instead (new `wsl-timeout-tree-kill.ts`). Migration is not feasible there: `runProcessSync` hands `timeoutMs` straight to Node's `spawnSync`, which has the identical root-only-kill defect -- there is no termination barrier on the sync path, so switching to it would fix nothing. The fallback taskkill is gated through `admitProcessTreeKill` (`win-taskkill-tree` scope), the same pid-recycling guard `signalProcessTree` uses, since by the time `execFileSync` throws `ETIMEDOUT` the root is already reaped and its pid is back in Windows' recycling pool. `listWslDistros` (`wsl --list --quiet`) gets the identical fix, not an exemption: its execFileSync option literal is byte-identical to `wslUncDirectoryExists`'s and `getWslHome`'s (`stdio`, `timeout: 5000`, `cwd`). `wsl --list` staying up during the original incident was an empirical observation about that one wedge, not a structural property of this code path -- nothing distinguishes it from the other two probes. Also: `windowsHide` was absent on all three sync sites (only `execFileUtf8` set it), so a hung probe could flash a visible console window. Added to all three in the same commit -- same option literal. Red-green: stashed wsl.ts + wsl-timeout-tree-kill.ts (source only, kept the new/updated tests) and ran `corepack pnpm vitest run --config config/vitest.config.ts src/main/wsl.test.ts src/main/wsl-timeout-tree-kill.test.ts src/main/wsl-running-distros.test.ts src/main/wsl-distro-list-single-flight.test.ts` against that reverted tree: 25 failed / 41 passed (4 files). Restored the source and re-ran: 168 passed / 11 skipped, 0 failed, across the full `src/main/wsl` suite. Co-Authored-By: Claude Opus 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change migrates asynchronous WSL probes from callback-based Merge Risk: ⚪ Minimal · up to Timed-out WSL probes now clean up process trees through the intended async and synchronous paths, with no unresolved material risk identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the defect, remediation strategies, affected probes, and verification results. It does not follow the required template structure and omits required or incomplete sections, including ELI5, What Changed, Linked Issue with Resolution Rewrite the description using every required template heading. Add an ELI5 summary, structured change and rationale sections, a Linked Issue entry using
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 |
There was a problem hiding this comment.
Important
This PR breaks the child_process import boundary — src/shared/child-process/child-process-import-boundary.test.ts fails with two assertions, so CI will block merge.
Reviewed changes
- Sync-probe tree-kill fallback — a new
killIfTimedOut/killTimedOutWslProcessTree(wsl-timeout-tree-kill.ts) walks the wsl.exe tree afterexecFileSyncreaps the root, gated throughadmitProcessTreeKill. - Async-probe migration —
execFileUtf8(extracted towsl-exec-utf8.ts) andwslUncDirectoryExistsAsyncmove torunProcesswithterminationBarrier: true, inheriting the #19319 tree-kill andwindowsHide. - Sync-probe
windowsHide— added towslUncDirectoryExists,listWslDistros, andgetWslHome, which previously flashed a console.
The approach is sound: the async paths reuse the existing termination barrier, and the sync paths correctly observe that runProcessSync has the identical root-only-kill defect it would solve nothing by migrating to. The residual recycled-pid risk on the sync taskkill is honestly documented and bounded by the same own-Chromium gate signalProcessTree uses. The one blocking problem is a repo-boundary violation, not a logic error.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| @@ -0,0 +1,55 @@ | |||
| import { spawnSync } from 'node:child_process' | |||
There was a problem hiding this comment.
import { spawnSync } from 'node:child_process' is a new direct child_process importer outside src/shared/child-process/, which breaks child-process-import-boundary.test.ts (I confirmed locally: 2 assertions fail — "has no direct importer outside the allowlist" and "holds the offender count at the pin", because this file becomes offender #156 against a pin of 155 and is absent from the allowlist). Route the taskkill through the chokepoint instead.
Technical details
# taskkill spawn must go through the child-process chokepoint
## Affected sites
- src/main/wsl-timeout-tree-kill.ts:1 — direct `node:child_process` import
- src/main/wsl-timeout-tree-kill.ts:37 — the raw `spawnSync('taskkill', ...)`
## Required outcome
- No new direct `child_process` import outside `src/shared/child-process/`; `child-process-import-boundary.test.ts` green.
## Suggested approach
- Replace the raw `spawnSync` with `runProcessSync({ program: 'taskkill', args: ['/pid', String(pid), '/t', '/f'], timeoutMs: 2000 })` from `src/shared/child-process/run-process`. The PR's own caveat (that `runProcessSync` has the root-only-kill defect) applies to the *probe*, not the kill — a `taskkill` is the kill itself, so there is no tree to terminate behind it. `runProcessSync` already resolves `windowsHide`/`shell:false` and swallows `ETIMEDOUT` into `timedOut`, which is fine for a best-effort kill.
- Or move the synchronous tree-kill into `src/shared/child-process/process-tree-termination.ts` (the owner directory, which is exempt) next to the existing async `taskkillTree`, and import it from `wsl-timeout-tree-kill.ts`. Do not add `src/main/wsl-timeout-tree-kill.ts` to the allowlist — the ratchet only shrinks and the offender pin (155) is a literal, so an allowlist addition alone still fails.
Same defect class as #19319, different mechanism. #19319 fixed the
runProcesspath (terminationBarrier); this fixes theexecFile/execFileSyncpath insrc/main/wsl.ts, where Node's timeout kills only the direct child and leaves the console host behind on Windows.Sites
wslUncDirectoryExists/wslUncDirectoryExistsAsynclistWslDistros(wsl --list --quiet)getWslHome/getWslHomeAsyncwindowsHide: truewas also absent on three of these, so the probes could flash a visible console.Sync vs async, and why not a single mechanism
The async paths migrate to
runProcess+terminationBarrier: true. The sync paths cannot:runProcessSynchandstimeoutMsstraight tospawnSync, which has the identical root-only-kill defect — there is no termination barrier on the sync path, so migrating them would fix nothing. They instead get a bounded, synchronoustaskkill /pid <pid> /t /fin the catch block, routed through the sameadmitProcessTreeKillguardsignalProcessTreeuses, because by the timeexecFileSyncthrowsETIMEDOUTthe root is already reaped.On
listWslDistrosAn earlier draft of this work proposed exempting the
wsl --listprobes, on the grounds thatwsl --listkept working during the incident that prompted #19316. That is an empirical fact about one wedge, not a structural difference — its option literal is byte-identical to the other two sync sites. It gets the same fix.Verification
Test Files 4 failed,Tests 25 failed | 41 passed.src/main/wsl→ 178 passed | 11 skipped, independently re-run by the author of this PR.oxlintclean;oxfmt --checkclean after formatting;check-max-lines-ratchet.mjsOK (execFileUtf8extracted towsl-exec-utf8.tsto stay inside the 300-line budget).Note for reviewers:
corepack pnpmon a Windows checkout currently re-triggerspostinstalland fails anode-gyprebuild of@vscode/windows-process-tree, unrelated to this change; the suite was run via the vitest binary directly.Relates to #19316.
🤖 Generated with Claude Code