-
-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Determine when child process terminates unexpectedly (crashes) #85
Comments
Hi. Hm. The exited event should definitely cover non-graceful termination as well. What do you experience instead? Does it hang? How exactly is the process getting terminated? |
Hi I've put a breakpoint on the 'exit' event, but it was never called and in fact the main process just hanged, waiting for more events from the Observable. The way the process terminated was by me killing it via Windows' Task Manager. |
Can you see if it also hangs when you use other execution models (i.e. |
With Command command = Cli.Wrap(filePath)
.WithArguments(arguments)
.WithValidation(CommandResultValidation.ZeroExitCode);
var result = await command.ExecuteAsync(stoppingToken);
_logger.LogInformation("Result: {result}", result); The last log line was never printed after killing the child process |
I just tried the following code: [Fact]
public async Task Test()
{
// Arrange
var cmd = Cli.Wrap("dotnet")
.WithArguments(a => a
.Add(Dummy.Program.FilePath)
.Add(Dummy.Program.Sleep)
.Add(100_000));
// Act
await cmd.ExecuteAsync();
// Assert
Assert.True(true);
} This is using the dummy program from tests and this command causes it to sleep for 100 seconds. While it was waiting, I killed it with task manager and It seems I can't reproduce your issue. Could it be that there's something special in your setup? |
This is weird.. are you running on Linux? or Windows? Can you try setting up a simple console app, spawning some process, and kill it as well via Task Manager? |
Yes, I'm running it on Windows. Console or test shouldn't make a difference, but I'll try. |
Tried it on a console, works the same way. Can you try the same thing but with bare |
I am having this same problem with one particular process. It's launched with "cmd /c mycommand.cmd". It stops yielding events when it has exited. It's a normal cmd file that exits with zero status. My code: await foreach (var cmdEvent in cmd.ListenAsync())
{
switch (cmdEvent)
{
case StartedCommandEvent start:
write(v, cname, "Start pid " + start.ProcessId);
RunningPid[index] = start.ProcessId;
break;
case StandardOutputCommandEvent stdOut:
write(v, cname, stdOut.Text);
break;
case StandardErrorCommandEvent stdErr:
write(v, "red", stdErr.Text);
break;
case ExitedCommandEvent ex:
return (ex.ExitCode, 0);
default:
write("UNK", "red", "Unknown event :" + cmdEvent.ToString());
break;
}
} I also confirmed in debugger that process exited event was emitted: // in ProcessEx.cs
public void Start()
{
// Hook up events
_nativeProcess.EnableRaisingEvents = true;
_nativeProcess.Exited += (_, _) =>
{
ExitTime = DateTimeOffset.Now; // THIS was called
_exitTcs.TrySetResult(null);
}; ... so it's some kind of race condition somewhere? Further debugging indicated that TrySetResult returned true (success) and the following await statement blocked forever: // Command.Execution.cs
try
{
// Wait until piping is done and propagate exceptions
await pipingTask.ConfigureAwait(false);
} @Tyrrrz do you think this is enough information to reopen the ticket? I can do further diagnostics if needed |
Yes, please do. |
I think you need to do it, I don't have the rights |
Hello,
I'm using CliWrap with the following flavor:
Is there any way I can determine the child process being spawned by CliWrap crashes? (which in that case I'd want to restart it..)
Initially I expected to it to be covered by the following case:
However, this only catches the case of graceful termination.
Hope my question is clear..
Thanks for helping!
The text was updated successfully, but these errors were encountered: