Skip to content

Stop a program whose output readers can't start, and warn when -KillTreeOnExit can't reach a program's tree - #111

Merged
HalRiveria merged 3 commits into
mainfrom
fix/4.2-start-rollback-and-tree-warning
Dec 2, 2026
Merged

HalRiveria merged 3 commits into
mainfrom
fix/4.2-start-rollback-and-tree-warning

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Three changes for 4.2, together in one PR:

A program whose output readers can't start is stopped. Start-PkProcessCore started the stdout and stderr reader threads (PkStreamReadTask.Run) only after the program was running, on both start paths, with nothing to undo the start if one failed. If a reader thread couldn't be created, the start threw without returning the program, so the batch and the dispatcher had nothing to kill: the program kept running untracked, with nothing reading its output. Now the readers start in a try; on a failure the program and what it started are stopped (Stop-PkProcessTree), a reader that never started is closed, and the start fails with "could not start ... its output couldn't be read", which the batch and the dispatcher report as a StartError.

-KillTreeOnExit warns when it can't reach a program's tree. It kills through the program's own Job Object. For a program without one (Windows refused it, the kit has no Job Object, or a custom starter started the program), it did nothing, silently. Stop-PkExitedJobTree, which all three engines use for it, now warns once per process. The README's -KillTreeOnExit paragraph and the parameter help say so, and add that StartMode CreatedInJob describes how programs start, not whether each one got its own Job Object.

"Choosing limits" says each running program takes two threads, one per output stream.

C#: a test hook, PkStreamReadTask.TestFailRunAfter, makes a reader start throw; PkChildProcessJob gets HasTree and a once-only claim for the new warning. TypesVersion goes from 14 to 15, so a session that loaded an older copy needs a new window.

Tests (failing before the change, on Windows PowerShell 5.1):

  • Section AW: the stdout or the stderr reader failing to start, on the CreateProcess path and the Process.Start path, and the stderr one in a batch. Before: 5 [FAIL], each with the program and its child (2 processes) left running. After: each start fails with "could not start" and nothing is left running.
  • Section BJ: a program without a tree job under -KillTreeOnExit, in the batch and the dispatcher (no tree job) and Invoke-PkProcessWithTimeout (Windows refusing it): the child is still left alone, now with one warning naming -KillTreeOnExit, and a second program in the same process gets no second warning. Before: 4 [FAIL], 0 messages.

The full harness passed on Windows PowerShell 5.1 and PowerShell 7.6.2, one after the other (748 assertions each), -AsModule -Section MODULE on both, and Build/Update-ParallelKitCSharp.ps1 -Check -Compile (csc.exe 4.8 as C# 5 and the .NET 10 SDK at LangVersion 5, no warnings).

@HalRiveria-Bot HalRiveria-Bot mentioned this pull request Dec 2, 2026
@HalRiveria
HalRiveria merged commit b117f6f into main Dec 2, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/4.2-start-rollback-and-tree-warning branch December 2, 2026 19:46
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