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: drieseng **
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: drieseng **
The timing for releasing the next stable depends on whether I can consider this regression fixed or now.
It'd be great if you could use the latest SVN build.
I consider it more stable than the latest beta, and - unless new regressions are discovered - this will be very close to the next official release (although I may release another beta first).