ObjectDisposedException Exception on SendKeepAlive()

Nov 10, 2014 at 11:45 AM
Edited Nov 10, 2014 at 11:57 AM
Hello all

I'm using the ssh.net library in a project, which creates quite a lot of SSH connections to a host. For this I am using a pool of open SSH connections and disconnect them after a while if not used.

Establishing a connection is done as follows:
SshClientObject = new SshClient(_Host, _Username, _Password);
SshClientObject.KeepAliveInterval = new TimeSpan(0,0,1,0);
SshClientObject.Connect();
Disconnect is done as follows:
SshClientObject.Disconnect();
SshClientObject.KeepAliveInterval = new TimeSpan(-1);
SshClientObject.Dispose();
SshClientObject = null;
In rare cases I have an unhandled exception, which terminates the application (Windows Service):

at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at Renci.SshNet.Session.SocketWrite(Byte[] data)
at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.BaseClient.SendKeepAlive()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()

It seems that even when I set the KeepAliveInterval to -1 (should disable), the KeepAlive timer seems to fired after I have disposed the object.

I would think that disposing an object also stops all timers, expechally when I first disable the KeepAliveInterval.

Any idea how I could prevent this exception?

I'm using the latest stable Version (2013.4.7).

Philipp
Coordinator
Nov 22, 2014 at 4:05 PM
Fixed in beta 2.
Marked as answer by drieseng on 11/22/2014 at 9:05 AM