Skip to content

Leave a disposed process out of a tree kill, and mark a finished job before disposing it - #47

Merged
HalRiveria-Bot merged 1 commit into
mainfrom
fix/disposed-process-kill
Nov 17, 2026
Merged

HalRiveria-Bot merged 1 commit into
mainfrom
fix/disposed-process-kill

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong: PowerShell reads HasExited and Id on a disposed Process as $null without throwing. Stop-PkProcessTree therefore counted a disposed process as alive and gave taskkill an empty /PID, which failed taskkill for the whole list. The fallback Kill() only reached the top-level processes, and the final WaitForExit then threw. This was reachable through the public API: a custom -JobFinalize that calls Complete-PkProcess -Dispose and then throws left every other running job's children running, although the README says a callback exception kills running processes.

What changed:

  • Stop-PkProcessTree only lists a process whose HasExited is $false and whose Id is set, and each final WaitForExit has its own try.
  • In the three finalize passes, a job is marked SlotReleased before its slot is released and its process disposed. A stop landing in between no longer leaves the teardown a disposed process to kill and a slot to release a second time. The force-stop now does its steps in the same order as the teardown.

Tested: two new harness assertions, both failing before the fix on 5.1 and 7:

  • The dispose-then-throw -JobFinalize with three cmd /c ping jobs running. Before the fix all 3 pings were left running; after, none.
  • Stop-PkProcessTree given a disposed process next to a live cmd /c ping tree. Before the fix it threw ("No process is associated with this object") and left the ping running; after, it kills the tree and returns $true.

The reordering itself has no direct test, because the window is between two statements. Full harness passes on Windows PowerShell 5.1 and PowerShell 7.

🤖 Generated with Claude Code

…before disposing it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit 6739f20 into main Nov 17, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/disposed-process-kill branch November 17, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants