Hanging indefinitely while trying to write to the stream

Apr 13, 2015 at 3:49 AM
If written some threaded code that makes use of this library. A simplified version of my code looks like this:
while (!stopThread)
    if ([there is new input])

        output = ShellStream.Expect(regex prompt, timeout);


During testing, I've discovered that if I establish a connection, then disconnect my network cable (because network dropouts are a real possibility for the application I'm making), this code hangs indefinitely at the ShellStream.WriteLine method. At always straight away, I'll sometimes get a couple of null outputs first, but eventually it just hangs.

I know that ShellStream has a way of setting a write timeout, but I get a "this stream does not support timeouts" message if I try that.

I've debugged using the SSH.Net code, and I see that an SshConnectionException is thrown, and objects start trying to Dispose. The point at which it gets stuck is in Session.cs, at line 673: "_messageListenerCompleted.WaitOne();"

Is there a solution to this?
Apr 14, 2015 at 3:38 PM
I'm not sure about the why but at line 673: "_messageListenerCompleted.WaitOne();" you can add a timemout value in the WaitOne() method.
Apr 15, 2015 at 12:48 AM
I didn't want to mess with the source code of the SSH library in case it caused some further error.

My stopgap solution was to encapsulate any call that might throw the exception that triggers the dispose inside it's own thread. If the thread doesn't complete within a specified time, I interrupt it. Less than ideal, but it works for the moment.