Handle exception thrown by ProcessName during ProcessEx timeout (#23990)

* Handle exception thrown by ProcessName during ProcessEx timeout

* Update src/Shared/Process/ProcessEx.cs

Co-authored-by: Brennan <brecon@microsoft.com>

* PR feedback

Co-authored-by: Brennan <brecon@microsoft.com>
This commit is contained in:
Stephen Halter 2020-07-16 15:13:24 -07:00 committed by GitHub
parent 5bc2c49ed5
commit 6940249de2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -49,10 +49,15 @@ namespace Microsoft.AspNetCore.Internal
_exited = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
// We greedily create a timeout exception message even though a timeout is unlikely to happen for two reasons:
// 1. To make it less likely for Process getters to throw exceptions like "System.InvalidOperationException: Process has exited, ..."
// 2. To ensure if/when exceptions are thrown from Process getters, these exceptions can easily be observed.
var timeoutExMessage = $"Process proc {proc.ProcessName} {proc.StartInfo.Arguments} timed out after {DefaultProcessTimeout}.";
_processTimeoutCts = new CancellationTokenSource(timeout);
_processTimeoutCts.Token.Register(() =>
{
_exited.TrySetException(new TimeoutException($"Process proc {proc.ProcessName} {proc.StartInfo.Arguments} timed out after {DefaultProcessTimeout}."));
_exited.TrySetException(new TimeoutException(timeoutExMessage));
});
}