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

Commented Issue: NullReferenceException in Renci.SshNet.BaseClient.IsConnected() [1485]

$
0
0
Hi,

while using Renci SSH Client successfully in production, I noticed a really rare error that just occurred on my dev machine:

```
4491 - OXE Control Center Gui: 15:08:15.9481613 - [Remote Connector] 10.132.142.192: Detected stop flag, terminating remote connection...
2482 - OXE Control Center Gui: 15:08:16.0824215 - [Remote Connector] 10.132.142.192: Error on connection check!

Source: Renci.SshNet

Message:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected)
bei Renci.SshNet.Session.get_IsConnected()
bei Renci.SshNet.BaseClient.get_IsConnected()
bei NextiraOne.Processors.RemoteConnector.IsConnected() in C:\Users\nsk\Documents\Visual Studio 2010\Projects\9 - NextiraOne Libraries\NextiraOne.Core\SP_RemoteConnector.cs:Zeile 393.
```

Notice my generic log message prefixes from my wrapper class around Renci.SshNet that tells us what happened here and in what short timeframe this occurs:
My program execution was stopped due to the internal stop flag and immediately after that the connection state was checked (don't think about the use case as I have a complicated multithreaded environment in which this check may be optimized/blocked at this stop situation, but this is a different topic :D )

The excpected result from IsConnected() is false here.

This is not severe, as my connection check treats errors equal to false. But just to improve Renci.SshNet I post this case here. :)

"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." means in english kind of "The object reference does not point to an object".

Regards,
Nicolas
Comments: ** Comment from web user: olegkap **

Hi,

Thanks for looking into it.
From what I see the only reason why this error can occur in IsConnectioned method is because while testing the connection socket was closed and disposed.
If this error occurs again and you can get it somewhat consistent you can try update IsConnected method as follow:
```
partial void IsSocketConnected(ref bool isConnected)
{
if (this._socket != null)
{
lock (this._socketLock)
{
isConnected = (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null)
&& this._socket.Poll(-1, SelectMode.SelectWrite);
}
}
else
{
isConnected = false;
}
}
```

And let me know if it solves it.
I will go ahead then and close this issue but will keep it in mind in case someone else reports it again or if it happens more often.

Thanks,
Oleg


Viewing all articles
Browse latest Browse all 1026

Trending Articles



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