Commit 9f2386d2 authored by Alessio Parma's avatar Alessio Parma

Update SystemCommandManager.cs

parent c36bd60f
......@@ -81,28 +81,21 @@ public sealed class SystemCommandManager : ICommandManager
try
{
command.Kill();
_logger.LogWarning("A timeout occurred while running {CommandName} with following arguments: {CommandArgs}. Configured timeout: {Timeout}", realCommandName, commandArgs, timeout);
throw new CommandException($"External command \"{realCommandName}\" exceeded the timeout of {timeout} milliseconds and it was killed", command.ExitCode);
}
catch (InvalidOperationException)
{
// The command already finished by itself.
goto WaitAgain;
command.WaitForExit();
}
_logger.LogWarning("A timeout occurred while running {CommandName} with following arguments: {CommandArgs}. Configured timeout: {Timeout}", realCommandName, commandArgs, timeout);
throw new CommandException($"External command \"{realCommandName}\" exceeded the timeout of {timeout} milliseconds and it was killed", command.ExitCode);
}
WaitAgain:
command.WaitForExit();
// From the docs of Process.WaitForExit(int): when standard output has been redirected
// to asynchronous event handlers, it is possible that output processing will not have
// completed when this method returns. To ensure that asynchronous event handling has
// been completed, call the WaitForExit() overload that takes no parameter after
// receiving a true from this overload.
if (command.ExitCode != 0)
{
var commandError = await command.StandardError.ReadToEndAsync().ConfigureAwait(false);
_logger.LogError("An error occurred while running {CommandName} with following arguments: {CommandArgs}. Command error: {CommandError}", realCommandName, commandArgs, commandError);
throw new CommandException($"External command \"{realCommandName}\" raised an error", command.ExitCode);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment