Unhandled exception

Mar 28, 2014 at 1:22 AM
Edited Mar 28, 2014 at 4:12 AM
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()

Any idea what could be the cause?

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

Many thanks,

Phil

ADDENDUM: I looked through the issues list and it seems very similar to issue #1840 behaviour...
Apr 3, 2014 at 11:31 PM
Edited Apr 3, 2014 at 11:31 PM
Bump.

As anyone run into this issue or know what could resolve it?

I've gone around the problem by using singleton instances of various connections I need and disposing them only on application exit but that's kind of a patch...

Many thanks,

Phil
Coordinator
Apr 6, 2014 at 6:15 PM
Hey Phil,

Can you submit an issue for this problem ?
Would it be possible to create a small repro ?

Thanks!
Gert
Apr 7, 2014 at 6:55 AM
Hi Gert,

I will open an issue right now.

It will be tough for me to reproduce since it was an error that was caught on a few occasions (on a few different installs) but it didn't seem to be related to a reproducible user scenario (or the users just didn't notice). Also, my code has been modified to work around this issue (I keep singleton shared instances of my SSH client objects).

As soon as I have a little bit of time, I'll pull out and older revision of my software where this was present and I'll try to clamp down on the issue.

Also, a while back I encountered another unhandled exception with the KeepAlive this time:

Description: The process was terminated due to an unhandled exception.
Exception Info:
System.Net.Sockets.SocketException
Stack:
at Renci.SshNet.Session.SocketWrite(Byte[])
at Renci.SshNet.Session.SendMessage(Renci.SshNet.Messages.Message)
at Renci.SshNet.BaseClient.SendKeepAlive()
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.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()

This is just something that would happen once in a while while the tunnel was opened and the KeepAlive were set to be sent. Again, I worked around this problem by opening the tunnel on-demand during operations only and thus I don't require the KeepAlive anymore.

Should I open an issue for this one as well?

Many thanks,

Phil
Coordinator
Apr 7, 2014 at 7:20 AM
Edited Apr 7, 2014 at 7:20 AM
Hi Phil,

Thanks for taking the time to revisit this issue.

Regarding the SendKeepAlive:
Please submit an issue if you can still reproduce this problem using the beta we released yesterday.

Thanks!
Gert