Skip to content

End what a program left running when its start is rolled back after it exited - #115

Merged
HalRiveria merged 1 commit into
mainfrom
fix/rollback-exited-program
Dec 3, 2026
Merged

HalRiveria merged 1 commit into
mainfrom
fix/rollback-exited-program

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Depends on #114, merge after it.

What was wrong: two places stop a program whose start has failed:

Both used Stop-PkProcessTree, which passes over a program that has already exited. If the program had exited by then, a child it left running (cmd /c start /b ...) was never stopped. It stayed in the kit's Job Object, so it ended with PowerShell at the latest. The rollback also left the program's process handle and its tree job's handle for the garbage collector.

What changed:

  • Both places kill the program's tree job first ([PkChildProcessJob]::KillTree), which reaches its children whether or not the program is still running. They fall back to Stop-PkProcessTree only when that fails (no tree job, as with StartMode NoJob).
  • The rollback now also releases the tree job's handle and disposes the process, as the dispatcher's cleanup already disposed it.
  • A harness-only hook, PkStreamReadTask.TestFailRunDelayMs, holds the failing reader start, so the program has exited by the time the rollback runs. Because that changes the C#, TypesVersion is now 16: a session that loaded an older copy has to be restarted.

How it was tested: harness section AW starts cmd /d /c start "" /b ping ... and makes its stderr reader fail after cmd.exe has exited, on both start paths, then checks the ping isn't left running. It also runs the dispatcher with a -JobStarter that waits for the same program to exit and then throws.

Before the fix (Windows PowerShell 5.1 and PowerShell 7, the same on both):

[FAIL] a program that has exited when its reader fails still has what it started ended, CreatedInJob (1 left running, ...)
[FAIL] a program that has exited when its reader fails still has what it started ended, Process.Start (1 left running, ...)
[FAIL] dispatch: a -JobStarter that throws after its program exited still has what the program started ended (1 left running, 1 start failure(s))

After: all three pass with 0 left running. Build/Update-ParallelKitCSharp.ps1 -Compile builds the C# with no warnings under both csc.exe (C# 5) and the .NET SDK (LangVersion 5).

Full harness: all 758 assertions pass on Windows PowerShell 5.1 and on PowerShell 7.

@HalRiveria
HalRiveria added this pull request to stack #118 December 3, 2026 00:28
@HalRiveria
HalRiveria force-pushed the fix/rollback-exited-program branch from d18f630 to 69ed874 Compare December 3, 2026 00:29
Base automatically changed from fix/abort-between-checks to main December 3, 2026 00:42
…t exited

When a program's output reader couldn't start, the rollback stopped the program with Stop-PkProcessTree, which passes over a program that has already exited, so a child it left running was never stopped. The dispatcher's cleanup when a -JobStarter throws after starting a program had the same gap. Both now kill the program's tree job first, which reaches its children whether or not it is still running, and fall back to Stop-PkProcessTree only when it has none. The rollback now also releases the tree job's handle and disposes the process, as the dispatcher's cleanup already disposed it.

A test hook, PkStreamReadTask.TestFailRunDelayMs, holds the failing reader start so the program has exited by then; TypesVersion is 16. Harness section AW covers the rollback on both start paths and the dispatcher's cleanup.
@HalRiveria
HalRiveria force-pushed the fix/rollback-exited-program branch from 69ed874 to a6a8d7c Compare December 3, 2026 00:42
@HalRiveria
HalRiveria merged commit 3920423 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/rollback-exited-program branch December 3, 2026 00:53
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