Quantcast
Channel: sshnet Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1026

Commented Issue: Session.Disconnect() hangs forever [2591]

$
0
0
I'm doing a reboot on a linux machine (dropbear ssh server) and disconnecting as fast as i can after that.
I'm using ssh.net 2014.4.6-beta2

The sshclient hangs in the Disconnect method (_messageListenerCompleted.WaitOne()), se comment below.

I'm guessing it hangs because the server (dropbear) disconnected the session before the client (renci.sshnet).

See the following discussion for more information:
[http://sshnet.codeplex.com/discussions/267304](http://sshnet.codeplex.com/discussions/267304)


```
private void Disconnect(DisconnectReason reason, string message)
{
_isDisconnecting = true;

// send disconnect message to the server if the connection is still open
// and the disconnect message has not yet been sent
//
// note that this should also cause the listener thread to be stopped as
// the server should respond by closing the socket
SendDisconnect(reason, message);

// disconnect socket, and dispose it
SocketDisconnectAndDispose();

if (_messageListenerCompleted != null)
{
// at this point, we are sure that the listener thread will stop
// as we've disconnected the socket
_messageListenerCompleted.WaitOne(); // <-- the code hangs here
_messageListenerCompleted.Dispose();
_messageListenerCompleted = null;
}
}
```
Comments: ** Comment from web user: PE **

Can someone please explain why this Dispose code won't work:

```
Public Overloads Sub Dispose()

Dim timeoutMutex As Mutex = New Mutex
Try
timeoutMutex.WaitOne()
SSHreader.DiscardBufferedData()
SSHreader.Dispose()
SSHwriter.Dispose()
SSHShell.Dispose()
ClientSsh.Disconnect()
ClientSsh.Dispose() ' this is the hang forever
timeoutMutex.ReleaseMutex()
timeoutMutex.Dispose()

Catch ex As Exception
' catch mutex timeout
End Try
End Sub
```
I expect that either the ClientSsh.Dispose() to work or that the mutex will run in a timeout and thereby end ClientSsh, (of type Renci.SshNet.SshClient) and any threads still running within ClientSsh.

Regards, Paul


Viewing all articles
Browse latest Browse all 1026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>