Skip to content

Check a killed program's tree job too, and warn when Windows won't end it - #133

Merged
HalRiveria merged 6 commits into
mainfrom
fix/tree-check-after-kill
Dec 3, 2026
Merged

HalRiveria merged 6 commits into
mainfrom
fix/tree-check-after-kill

Conversation

@HalRiveria-Bot

@HalRiveria-Bot HalRiveria-Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

A time-limit kill (the dispatcher's, the batch's or Invoke-PkProcessWithTimeout's) or an abort's force-stop ends a program through its own Job Object. If Windows wouldn't end that Job Object, the kill fell back to taskkill /T. That kills the program and its running children, but misses a child whose parent has already exited. The kill still counted as complete, with no warning. The README says both kill a program "and anything it started".

What changed

  • After every kill, the program's Job Object is ended once more. That second try only fails if Windows refuses, since by then the Job Object is empty.
  • A refusal now gives a warning, once per session, naming the process and the reason (its time limit, an abort, a force-stop). It shares -KillTreeOnExit's once-per-session warning for the same refusal, so you get one or the other, not both.
  • A time-limit kill whose check is refused still sets TimedOut.
  • The README's note on killing a program's tree mentions the warning.
  • The comments in the kit and the C# are cut to a sentence or two each, with history narration taken out; help blocks are unchanged. Four harness comments that told what the code used to do now say what the test checks.
  • From a code review of everything merged since 4.2's review round (Read a job's CancelToken case-insensitively, and refuse keys that differ only in case #126-Bring drifted copies back in step, and fix comments that no longer match the code #132) plus this branch:
    • The harness watchdog could take a beat file removed at the end of a passing run for a hang (a missing file reads as written in 1601) and kill the run. It now skips a missing file.
    • The batch groups repeated start failures by the innermost error message, so a failure note naming the process doesn't stop repeats from being counted.
    • Invoke-PkProcessWithTimeout's cleanup names a stopped script, not a force-stop, in its warning.
    • Its time-limit error now says when the program couldn't be killed, instead of "- killed".
    • Shorter comments for this round's harness and workflow notes, and "canceled" spelled the American way.
  • A second comment pass, as a code review of the whole kit, harness, C#, build scripts and workflows:
    • Fixed a note that named the wrong caller of a result, an empty catch that had lost its reason, an out-of-date function header, and five harness catches with no reason.
    • Cut long comment blocks in the harness, the C# and the workflows to a sentence or two.
  • A readability pass over every comment, for a reader who has only this repo:
    • Comments that leaned on unexplained shorthand now name what they mean: the function, key, switch or limit.
    • Several that no longer matched their code are corrected, for example a loop's three start paths and a leaked-value example.

How it was tested

Six new section BJ assertions. A program runs on while its child starts a tagged ping through a .cmd file and exits at once. Each case kills the program:

  • through the dispatcher's time limit;
  • through an abort's force-stop;
  • through Invoke-PkProcessWithTimeout's time limit.

Each case runs with and without TestFailTerminate. Without it, nothing is left running and there's no warning. With it, the ping is left running, there's exactly one warning, and the test kills the ping by its tag.

Before the fix (main's kit with the new harness), on 5.1 and 7 alike:

  [FAIL] a time-limit kill whose tree job Windows won't end says what may still be running, once (pings left 1, 0 warning(s))
  [FAIL] an abort's force-stop whose tree job Windows won't end says what may still be running, once (pings left 1, 0 warning(s))
  [FAIL] Invoke-PkProcessWithTimeout's limit whose tree job Windows won't end says what may still be running, once (pings left 1, 0 warning(s))
3 FAILED, 45 passed

After, and again after the review's fixes and the comment passes: the full harness passes on Windows PowerShell 5.1 and PowerShell 7 (812 assertions each). A second review pass found no code issues. Build/Update-ParallelKitCSharp.ps1 -Compile builds the C#, which changed only in comments, with no warnings.

…d it

A time-limit kill or a force-stop whose tree job Windows wouldn't end fell back to taskkill /T, which misses a child whose parent has already exited, and counted the kill as complete. After every kill the tree job is now ended again (a second TerminateJobObject fails only on a refusal), and a refusal is warned about once per session, sharing -KillTreeOnExit's warning for the same refusal.
The kit's and the C#'s comments are cut to what the code does and why, in a sentence or two, with history narration taken out; help blocks are unchanged. Four harness comments that told what the code used to do now say what the test checks.
The harness watchdog no longer takes a beat file removed at the end of a run for a hang. The batch groups repeated start failures by the innermost message, which a rollback's note naming the process doesn't change. Invoke-PkProcessWithTimeout's cleanup names a stopped script, not a force-stop, in its warning, and its time-limit error says when the program couldn't be killed. Stop-PkProgramTree's comment names the force-stop's copy of its check.
A stale note on who reads Stop-PkProcessTreeCore's result, an empty catch that lost its reason, Stop-PkJobProcess's out-of-date header, empty harness catches with no reason, and long comment blocks in the harness, the C# and the workflows cut to a sentence or two.
Comments that leaned on unexplained shorthand now name what they mean (the function, key, switch or limit), several that no longer matched their code are corrected (the loop's three start paths, a leaked-value example, the paused handler thread), and two that cited version numbers say which PowerShell.
@HalRiveria
HalRiveria merged commit f7dee9b into main Dec 3, 2026
6 checks passed
@HalRiveria
HalRiveria deleted the fix/tree-check-after-kill branch December 3, 2026 21:36
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