Hi Oleg,
I found a bug in how you are handling disposing of SftpClient (and possibly other clients). In short I use SftpClient in a using{} block, during Dispose it is possible that an Exception can occur closing the Channel (e.g. SocketException), which lead to not setting GC.SuppressFinalize and eventually the objects will be GC'd by the framework which leads to another exception being thrown, one which I am obviously unable to catch.
Here is the stack trace of the exception being thrown during standard Dispose from using{} block (note this exception I'm catching at the moment):
I found a bug in how you are handling disposing of SftpClient (and possibly other clients). In short I use SftpClient in a using{} block, during Dispose it is possible that an Exception can occur closing the Channel (e.g. SocketException), which lead to not setting GC.SuppressFinalize and eventually the objects will be GC'd by the framework which leads to another exception being thrown, one which I am obviously unable to catch.
Here is the stack trace of the exception being thrown during standard Dispose from using{} block (note this exception I'm catching at the moment):
System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
at Renci.SshNet.Session.SocketWrite(Byte[] data) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\Session.NET.cs:line 178
at Renci.SshNet.Session.SendMessage(Message message) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\Session.cs:line 742
at Renci.SshNet.Channels.Channel.Close(Boolean wait) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\Channels\Channel.cs:line 523
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\Channels\ChannelSession.cs:line 108
at Renci.SshNet.Channels.Channel.Dispose(Boolean disposing) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\Channels\Channel.cs:line 706
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean disposing) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\SubsystemSession.cs:line 224
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean disposing) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\Sftp\SftpSession.cs:line 234
at Renci.SshNet.SftpClient.Dispose(Boolean disposing) in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\SftpClient.cs:line 1578
at Renci.SshNet.BaseClient.Dispose() in d:\Temp\sshnet-22965\Renci.SshClient\Renci.SshNet\BaseClient.cs:line 210
And here is the exception that follows when .NET does it's garbage collection on this same SftpClient (this exception I cannot catch):Exception Info: Renci.SshNet.Common.SshConnectionException
Stack:
at Renci.SshNet.Session.SendMessage(Renci.SshNet.Messages.Message)
at Renci.SshNet.Channels.Channel.Close(Boolean)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean)
at Renci.SshNet.Channels.Channel.Dispose(Boolean)
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SubsystemSession.Finalize()