We are facing an unhandled exception during Dispose of the SftpClient.
2013-05-13 12:54:22,711 [2] FATAL - AppDomain.UnhandledException
Renci.SshNet.Common.SshConnectionException: Client not connected.
at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.Channels.Channel.Close(Boolean wait)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait)
at Renci.SshNet.Channels.Channel.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean disposing)
at Renci.SshNet.SftpClient.Dispose(Boolean disposing)
at Renci.SshNet.BaseClient.Finalize()
This happens when the connection to the Ssh server is lost and affects our ability to gracefully handle situations when servers/connectivity goes down. O
The solution I suggest to swallow any exceptions coming from SftpClient.Dispose() as follows. Not pretty but as a general rule, Dispose shouldnt be throwing exceptions, unless such exceptions are symtomatic of a more serious problem.
Cheers
protected override void Dispose(bool disposing)
{
try
{
if (this._sftpSession != null)
{
this._sftpSession.Dispose();
this._sftpSession = null;
}
if (this._disposeConnectionInfo)
((IDisposable)this.ConnectionInfo).Dispose();
base.Dispose(disposing);
}
catch
{
// swallow it
}
}
2013-05-13 12:54:22,711 [2] FATAL - AppDomain.UnhandledException
Renci.SshNet.Common.SshConnectionException: Client not connected.
at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.Channels.Channel.Close(Boolean wait)
at Renci.SshNet.Channels.ChannelSession.Close(Boolean wait)
at Renci.SshNet.Channels.Channel.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean disposing)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean disposing)
at Renci.SshNet.SftpClient.Dispose(Boolean disposing)
at Renci.SshNet.BaseClient.Finalize()
This happens when the connection to the Ssh server is lost and affects our ability to gracefully handle situations when servers/connectivity goes down. O
The solution I suggest to swallow any exceptions coming from SftpClient.Dispose() as follows. Not pretty but as a general rule, Dispose shouldnt be throwing exceptions, unless such exceptions are symtomatic of a more serious problem.
Cheers
protected override void Dispose(bool disposing)
{
try
{
if (this._sftpSession != null)
{
this._sftpSession.Dispose();
this._sftpSession = null;
}
if (this._disposeConnectionInfo)
((IDisposable)this.ConnectionInfo).Dispose();
base.Dispose(disposing);
}
catch
{
// swallow it
}
}