Repository navigation
End a program's tree through one function, and say when a failed start leaves something running - #131
Merged
Merged
Conversation
…t leaves something running Every kill path for one program now goes through Stop-PkProgramTree: the time-limit kill, -KillTreeOnExit, Invoke-PkProcessWithTimeout's kills and a failed start's rollback. The two rollbacks (a reader that can't start, a -JobStarter that throws after starting its program) share Stop-PkFailedStartTree, and when Windows won't end the program's tree job, or an exited program has none, the start's failure now says what it started may still be running instead of that it was stopped. Invoke-PkProcessWithTimeout's cleanup uses the force-stop's steps.
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
Ending a program and what it started was done in several places, each with its own steps and its own reporting:
-KillTreeOnExit;Invoke-PkProcessWithTimeout's kill and cleanup;-JobStarterthat throws after starting its program.They had drifted apart. When Windows wouldn't end the program's own Job Object, the two rollbacks fell back to
Stop-PkProcessTree, which skips a program that has exited, and said nothing. What the program had started kept running (until PowerShell exits), while the failure said the program "was stopped". Only-KillTreeOnExitwarned about it.What changed
One function,
Stop-PkProgramTree, for every kill path for one program.Stop-PkProcessTree: its own Job Object, elsetaskkill /T.-KillTreeOnExit(Stop-PkExitedJobTree, which keeps its once-per-session warnings), andInvoke-PkProcessWithTimeout's kill.Stop-PkProcessTreecall, sotaskkillruns once.The two rollbacks share
Stop-PkFailedStartTree. When something may still be running, the failed start says so instead of "so it was stopped":Example: "...its output couldn't be read (...). Its program (process N) has ended, but Windows wouldn't end its own Job Object, so what it started may still be running. That ends when PowerShell does."
A gap the review of this change found: a program still running at the rollback, whose Job Object Windows wouldn't end, was killed by
taskkill /T. That can miss a child whose parent has already exited. It's now reported as a refusal too.Invoke-PkProcessWithTimeout's cleanup uses the force-stop's steps (Stop-PkJobProcess) instead of its own copy.No C# change.
How it was tested
Three new section AW assertions. A tagged
pingis left behind bycmd /c start /b, and must be reported:TestFailTerminate;TestNoTreeJob;-JobStarterthat throws after its program exits, withTestFailTerminate.Each test kills its leftover ping by its tag.
Before (main's kit with the new harness), 5.1 and 7 alike:
After: the full harness passes on Windows PowerShell 5.1 and PowerShell 7 (806 assertions each). A first full run caught a regression in this change: a
Processthat was never started reads$nullforHasExited, and was taken as exited, so the time-limit kill lost its "couldn't be stopped" warning. It's now reported as unknown, as before.