Repository navigation
[patch] Treat a partly failed process-tree kill as best effort, so Cancel() never throws - #112
Merged
Merged
Conversation
…ncel() never throws Process.Kill(entireProcessTree: true) reports descendants it could not terminate (owned by another user, or elevated) as AggregateException, which TryKill did not catch. It escaped the cancellation registration out of the caller's Cancel(), replaced the OperationCanceledException RunAsync rethrows, and hid a handler's real exception. TryKill now catches it, and takes the kill as a parameter so a test can make it fail. Fixes #107 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bm33TiYrofqKs4oGc3UGUU
Resolve the RunCommandTests.cs conflict by keeping both sides' new tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JE3qjjjTXN28xUcTq2h6vD
SonarCloud S2699 flagged the test as having no assertion. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JE3qjjjTXN28xUcTq2h6vD
|
This was referenced Oct 6, 2026
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.



Fixes #107
Problem
Process.Kill(entireProcessTree: true)reports descendants it couldn't terminate asAggregateException, such as asudochild or an elevated process.TryKillcaught onlyInvalidOperationException,Win32ExceptionandNotSupportedException, so the exception escaped from all three call sites:cts.Cancel()threw, or withCancelAfter, the timer thread did.OperationCanceledExceptioncatch: it replaced the documentedOperationCanceledException.Change
TryKillnow also catchesAggregateException. The runtime's tree kill carries on past each failure, so everything it could kill has already been killed.Kill(Process), which keeps thenetstandard2.xsingle-process fallback.TryKill(Process)forwards to a newinternal TryKill(Process, Action<Process> kill), so a test can inject a kill that fails. The XML doc says why this method must never throw.Tests
New
CancelShouldNotThrowWhenTheTreeKillCannotTerminateEveryDescendant:sleep.TryKillwith a kill that throws the runtime'sAggregateException(Win32Exception)on a token, the same wayRunAsyncregisters its kill.cts.Cancel()returns normally, and that a directTryKillcall, as the catch blocks make it, doesn't throw either.Checked locally (Linux, net10.0):
catchremoved, the test fails with the exception coming out ofCancellationTokenSource.ExecuteCallbackHandlers, which is the issue'scts.Cancel()symptom.Not tested end to end: a real process tree with an unkillable descendant. As the issue says, a sandboxed root environment can't easily create one. The seam test covers the exception path that such a tree produces.
Independent of #110 and #111, which touch other parts of
RunAsyncandAsyncProcessStreamReader.🤖 Generated with Claude Code
https://claude.ai/code/session_01Bm33TiYrofqKs4oGc3UGUU
Generated by Claude Code