Quantcast
Channel: sshnet Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1026

Commented Issue: Unobserved exception rethrown by finalizer thread [1298]

$
0
0
<p>Hi,</p><br><p>&#160;</p><br><p>There is an unhandled System.AggregateException in a worker thread within SSH.NET version 18974 that causes the container application to crash. The exception should be caught and rethrown to the caller. This error occurs when the connection between the SHH client and server is flaky, i.e. it comes on and off. I added an AppDomain unhandled exception handler to log the exception. Here is the stack trace of the exception:</p><br><p>&#160;</p><br><p>ERROR: SubsystemSession.cs(128): Object reference not set to an instance of an object.</p><br><p>ERROR: SubsystemSession.cs(169): Renci.SshNet.Sftp.SubsystemSession.Session_ErrorOccured(Object sender, ExceptionEventArgs e) failed.</p><br><p>ERROR: System.EventHandler`1.Invoke(Object sender, TEventArgs e) failed.</p><br><p>ERROR: Session.cs(1929): Renci.SshNet.Session.RaiseError(Exception exp) failed.</p><br><p>ERROR: Session.cs(1592): Renci.SshNet.Session.MessageListener() failed.</p><br><p>ERROR: Session.cs(522): Renci.SshNet.Session.b__14() failed.</p><br><p>ERROR: System.Threading.Tasks.Task.InnerInvoke() failed.</p><br><p>ERROR: System.Threading.Tasks.Task.Execute() failed.</p><br><p>ERROR: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.</p><br><p>ERROR: Application domain unhandled exception.</p><br><p>&#160;</p><br><p>I am not too familar with Tasks, but I suspect the error could be fixed by adding a catch block to the try block at Session.cs, line 520, and rethrow the exception. I am posting this while I am trying to fix the issue in case someone else can help.</p><br><p>&#160;</p><br><p>Thanks,</p><br><p>&#160;</p><br><p>Robert</p><br>
Comments: ** Comment from web user: jsf75 **

Hi all,

My real problem is that a exception in sshnet makes my process been killed !

the call stack :

AggregateException := A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.
at System.Threading.Tasks.TaskExceptionHolder.Finalize()
NullReferenceException := Object reference not set to an instance of an object.
at Renci.SshNet.Sftp.SubsystemSession.RaiseError(Exception error) in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\SubsystemSession.cs:line 138
at Renci.SshNet.Sftp.SubsystemSession.Session_ErrorOccured(Object sender, ExceptionEventArgs e) in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\SubsystemSession.cs:line 194
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Renci.SshNet.Session.RaiseError(Exception exp) in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 1934
at Renci.SshNet.Session.MessageListener() in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 1597
at Renci.SshNet.Session.<Connect>b__4() in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 529
at System.Threading.Tasks.Task.Execute()

In my case, I have message = null in Session.cs, line 1584.

extract of session.Cs :
private void MessageListener()
{
try
{
while (this._socket != null && this._socket.Connected)
{
var __message__ = this.ReceiveMessage();

if (message == null)
{
throw new NullReferenceException("The 'message' variable cannot be null");
}

this.HandleMessageCore(message);
}
}
catch (Exception exp)
{
this.__RaiseError__(exp);
}
}

so, since MessageListener is called from Session line 529 :

this.__ExecuteThread__(() =>
{
try
{
this.__MessageListener__();
}
finally
{
this._messageListenerCompleted.Set();
}
});

-> MessageListener runs in an other thread... and receive a null message, which implies RaiseError Method, which uses

protected void RaiseError(Exception error)
{
this._exception = error;

__this._errorOccuredWaitHandle.Set();__

if (this.ErrorOccurred != null)
{
this.ErrorOccurred(this, new ExceptionEventArgs(error));
}
}

-> and it seems that session has been disposed before RaiseError() has been called, which leads to a null reference exception in line 138 of subsystemSession.cs

So, this uncatched exception makes the process stop (since this thread is not managed for exception handling) :

http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.unobservedtaskexception.aspx


I'm going to try to register to the event as you can see here :

http://stackoverflow.com/questions/8803107/task-and-exception-silence


I will let you know...



Viewing all articles
Browse latest Browse all 1026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>