Description
The IAsyncResult returned by Command.BeginExecute is not signaled in case of session error. Like for exemple a remote host rebooting during the command execution.
This prevent the use of .net async/await pattern like
await Task.Factory.FromAsync(command.BeginExecute, command.EndExecute, null);
To reproduce 👍 again a linux host, try this
using (var sshClient = new SshClient(connectionInfo))
{
sshClient.Connect();
using (var command = sshClient.CreateCommand(@"sleep 100000"))
{
command.CommandTimeout = TimeSpan.FromMinutes(1);
try
{
await Task.Factory.FromAsync(command.BeginExecute, command.EndExecute, null);
}
catch (Exception ex2)
{
Console.Write("Exception 1");
Console.Write(ex2.ToString());
}
}
}
While the program wait in the sleep, reboot the host.
The exception is never throw.
If you repeat this with a
command.Execute();
an exception in throw.
My analyze is that the wait handle used for session exception is not the same than the one in the IAsyncResult.