Description
I tried to update ssh.net to the latest version in my project and encountered a problem while testing my application.
The problematic change in ShellStream came with the commit “Fix a few issues with ShellStream (https://github.com/sshnet/SSH.NET/pull/1322)”. The method where the lock occurs is the read method in line 747 in the ShellStream.cs file. There is the following while loop:
while (_head == _tail && !_disposed)
{
_ = Monitor.Wait(_sync);
}
But since _head == _tail returns true and the server sends no further response, the Monitor.Wait method does not return.
Before the change, it only checked if _incoming.Count > 0.
Is there a reason for this change that I can't see, or is it an error?
Edit: Maby a little bit more context could be nice
try
{
_shell = _shellStreamClient.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
_reader = new StreamReader(_shell);
_writer = new StreamWriter(_shell)
{
AutoFlush = true,
NewLine = "\n"
};
_writer.Write("/tmp/power.sh\n");
while (true)
{
if (DateTime.Now.Subtract(startTime) > timeout)
{
throw new TimeoutException("Timeout message [...]");
}
var output = _reader.ReadLine(); // The application locks here
if (output == null || output == "")
{
Thread.Sleep(100);
continue;
}
if (output.StartsWith("Enter on, off"))
{
_writer.Write("on\n");
}
if (output.StartsWith("relay on"))
{
break;
}
}
}
catch
{
DisposeConnection();
throw;
}
I can't put the reader, writer and stream in using blocks because I continue to use them outside the method scope.