Skip to content

Commit 0403596

Browse files
authored
ProcessTerminationHandler: handle case where handler completes with an exception. (#2113)
1 parent 48faa68 commit 0403596

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/System.CommandLine/Invocation/ProcessTerminationHandler.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,20 @@ void Cancel(int forcedTerminationExitCode)
8080
{
8181
// request cancellation
8282
_handlerCancellationTokenSource.Cancel();
83-
84-
// wait for the configured interval
85-
if (!_startedHandler.Wait(_processTerminationTimeout))
83+
84+
try
85+
{
86+
// wait for the configured interval
87+
if (!_startedHandler.Wait(_processTerminationTimeout))
88+
{
89+
// if the handler does not finish within configured time,
90+
// use the completion source to signal forced completion (preserving native exit code)
91+
ProcessTerminationCompletionSource.SetResult(forcedTerminationExitCode);
92+
}
93+
}
94+
catch (AggregateException)
8695
{
87-
// if the handler does not finish within configured time,
88-
// use the completion source to signal forced completion (preserving native exit code)
89-
ProcessTerminationCompletionSource.SetResult(forcedTerminationExitCode);
96+
// The task was cancelled or an exception was thrown during the task execution.
9097
}
9198
}
9299
}

0 commit comments

Comments
 (0)