Repository navigation
Kill each program's whole tree through a Job Object of its own - #77
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…once a kill ends the tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
What was wrong
A time-limit kill, an abort's force-stop and
Stop-PkProcessTreeusedtaskkill /T, which finds a tree by parent PIDs. A program's descendant whose parent had already exited (astart /bhelper, or anything an exited intermediate started) has nothing linking it back, so it ran on until PowerShell exited.Reproduced on 5.1 and 7.6 with a program that runs an inner
cmdthat starts apingand exits, then pings itself:Stop-PkProcessTreekilled the program and its ownpingand left the orphan running.-TimeoutSecondstook 17.3 s, because the surviving orphan held its stdout for the full 15 s stream wait after the kill, and the orphan was still running afterwards.What changed
TryStartlists it after the kit's job inPROC_THREAD_ATTRIBUTE_JOB_LIST, so the program is in it from its first instruction.Process.Startfallback assigns it right after the kit's job.ConditionalWeakTablekeyed by theProcess, as aSafeHandle.Stop-PkProcessTreeCoreends a program that has a tree job withTerminateJobObject: the program and everything in its tree, orphans included, at once. Only programs without one go totaskkill. That's programs the kit didn't start,StartMode NoJob, or one Windows wouldn't end that way.Complete-PkProcessruns. Failing both, it goes when theProcessis collected.TryStartretries the start once without it. The program still starts, and a kill goes totaskkill. A program that can't start at all fails again with its own error.[PkState]::ThreadPoolRaised, unused since Leave the thread pool's minimum alone #76, is removed. New test-only hooks:TestNoTreeJob,TestRefuseTreeJob,TestHasTree.Stop-PkProcessTreeand the FAQ answer on stopping a program.How it was tested
New harness section BF, 7 assertions, on 5.1 and 7:
Stop-PkProcessTreekills the orphan and releases the tree job, on both start paths.taskkillstill kills its tree.PROCESS_TERMINATEis killed with the tree job.The existing
taskkill-path tests now start their programs withTestNoTreeJob, so they still reachtaskkill. Those are the 40-tree kill, AJ's protected child, AV's stand-intaskkilland the one-PID-per-call test. Without the hook, the argument-splitting test failed and the hang test passed without reachingtaskkill.The same check script against the old code and this branch, on both runtimes:
Stop-PkProcessTree300 quick programs took the same time on both, with no handle growth after a GC.
The full harness passed on 5.1 and then 7: 601 assertions each.
Not covered: a program that has a tree job where
TerminateJobObjectitself fails, which falls back totaskkill. I found no way to make Windows refuse that from a test.🤖 Generated with Claude Code