fix: force-kill the captured PET child so restart cannot lose or misfire the kill - #19
Open
StellaHuang95 wants to merge 2 commits into
Open
fix: force-kill the captured PET child so restart cannot lose or misfire the kill#19StellaHuang95 wants to merge 2 commits into
StellaHuang95 wants to merge 2 commits into
Conversation
…ire the kill killProcess() sent SIGTERM, scheduled a 500ms callback that re-read the mutable this.proc field, then cleared it synchronously. By the time the callback ran, this.proc was either already undefined (a hung PET was never SIGKILLed) or reassigned by a concurrent restart (the delayed SIGKILL could hit the healthy replacement). Extract killPetProcessWithGrace, which captures the child and clears the holder before signalling, so the delayed SIGKILL only ever targets that captured child. Add focused ownership regression tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Owner
Author
|
🔒 Automated review in progress — @StellaHuang95 is auto-reviewing this PR. |
StellaHuang95
commented
Aug 23, 2026
StellaHuang95
commented
Aug 23, 2026
…is not SIGKILLed A child that responds to SIGTERM reports exitCode === null with signalCode set, so guarding the escalation on exitCode alone still fired SIGKILL at an already-terminated child. Include signalCode in KillablePetProcess and only signal while both terminal-state fields are null; extend the test double with signalCode and cover the SIGTERM-during-grace case. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
Fixes a force-kill ownership bug in the PET (
python-environment-tools) child-process teardown insrc/managers/common/nativePythonFinder.ts.Problem
PET runs as a long-lived child process managed by
NativePythonFinderImpl. When a request times out or the RPC connection breaks, recovery callskillProcess()to terminate the hung child, thenrestart()spawns a fresh one intothis.proc. The teardown could act on the wrong process across that restart boundary.Root cause
killProcess()sentSIGTERM, scheduled a 500 mssetTimeoutthat re-read the mutablethis.procfield to decide whether toSIGKILL, then synchronously setthis.proc = undefined. When the callback ran,this.procwas either alreadyundefined(so a hung PET was neverSIGKILLed) or had been reassigned by a concurrent restart (so the callback couldSIGKILLthe healthy replacement).Fix
Extract
killPetProcessWithGrace(getProc, clearProc, outputChannel, graceMs), which captures the current child and clears the holder before signalling, then sendsSIGTERMand — after the grace period —SIGKILLs only that captured child.killProcess()delegates via() => this.proc/() => { this.proc = undefined; }. Because the delayedSIGKILLcloses over the captured local child rather than the mutable field, a concurrent restart's replacement is never targeted, and a hung child is reliably force-killed. The grace period is unchanged (KILL_PROCESS_GRACE_PERIOD_MS = 500). No PET source is touched and there is no extension-API change.Tests
nativePythonFinder.killProcess.unit.test.ts(6 cases, sinon fake timers):SIGTERM→SIGKILLon the captured child, synchronous ownership release, exit-during-grace not force-killed, already-exited child not signalled (holder still cleared), a replacement assigned during the grace period is never killed (key regression), andSIGTERMerrors are caught/logged without throwing. All 6 pass;npm run lintandnpm run compile-testsare clean.