Hello,
I have been using the SSH.Net library to connect to a remote SSH server to establish a DB connection between a VB client software and MySQL server. Everything works fine except sometimes the following exception is unhandled and crashes the application:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
at Microsoft.Win32.Win32Native.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle)
at System.Threading.EventWaitHandle.Set()
at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured(System.Exception)
at Renci.SshNet.Channels.Channel.Session_ErrorOccured(System.Object, Renci.SshNet.Common.ExceptionEventArgs)
at System.EventHandler`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Invoke(System.Object, System.__Canon)
at Renci.SshNet.Session.RaiseError(System.Exception)
at Renci.SshNet.Session.MessageListener()
at Renci.SshNet.Session.<Connect>b__4()
at Renci.SshNet.Session+<>c__DisplayClass3d.<ExecuteThread>b__3c(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
I am running with the code base downloaded on March 16th 2014.
My connect, disconnect code is pretty straightforward:
client = Nothing
client = New SshNet.SshClient(_host, _port, _user, key)
client.Connect()
portfw = Nothing
portfw = New SshNet.ForwardedPortLocal("localhost", 33306, "localhost", 3306)
client.AddForwardedPort(portfw)
portfw.Start()
...................
If isStarted Then
portfw.Stop()
End If
If isConnected Then
client.RemoveForwardedPort(portfw)
client.Disconnect()
End If
I looked through the issues list and it seems very similar to issue #1840 behaviour...
This seems to happen when the SshNet.SshClient is set to Nothing and disposed, i.e., Create SshClient, connect, create portFW, start, do some operations, stop portFW, remove portFW, disconnect SshClient, Set SshClient to Nothing.
Sometimes, this will result in the exception above.
Many thanks and cheers,
Phil
Comments: ** Comment from web user: ambientson **
I have been using the SSH.Net library to connect to a remote SSH server to establish a DB connection between a VB client software and MySQL server. Everything works fine except sometimes the following exception is unhandled and crashes the application:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
at Microsoft.Win32.Win32Native.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle)
at System.Threading.EventWaitHandle.Set()
at Renci.SshNet.Channels.ChannelDirectTcpip.OnErrorOccured(System.Exception)
at Renci.SshNet.Channels.Channel.Session_ErrorOccured(System.Object, Renci.SshNet.Common.ExceptionEventArgs)
at System.EventHandler`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Invoke(System.Object, System.__Canon)
at Renci.SshNet.Session.RaiseError(System.Exception)
at Renci.SshNet.Session.MessageListener()
at Renci.SshNet.Session.<Connect>b__4()
at Renci.SshNet.Session+<>c__DisplayClass3d.<ExecuteThread>b__3c(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
I am running with the code base downloaded on March 16th 2014.
My connect, disconnect code is pretty straightforward:
client = Nothing
client = New SshNet.SshClient(_host, _port, _user, key)
client.Connect()
portfw = Nothing
portfw = New SshNet.ForwardedPortLocal("localhost", 33306, "localhost", 3306)
client.AddForwardedPort(portfw)
portfw.Start()
...................
If isStarted Then
portfw.Stop()
End If
If isConnected Then
client.RemoveForwardedPort(portfw)
client.Disconnect()
End If
I looked through the issues list and it seems very similar to issue #1840 behaviour...
This seems to happen when the SshNet.SshClient is set to Nothing and disposed, i.e., Create SshClient, connect, create portFW, start, do some operations, stop portFW, remove portFW, disconnect SshClient, Set SshClient to Nothing.
Sometimes, this will result in the exception above.
Many thanks and cheers,
Phil
Comments: ** Comment from web user: ambientson **
Hi Gert,
I will try to get around to it shortly but I was not able to replicate that defect on a consistent basis.
Also, this is something that I worked around by keeping a handle on my connection object during the entire time my application is running (disposing only on exit).
Since my application is stable right now, I am not too keen on upgrading my SSH.NET version. Is the latest SVN build stable? How close are you to a new official release?
I'll revert to the old code and do a few tests and let you know.
Thanks,
Phil