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:
parent
5bc2c49ed5
commit
6940249de2
|
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue