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

Created Unassigned: NullReferenceException on Disconnect (possible race condition) [2652]

$
0
0
I am encountering a `NullReferenceException` when disconnecting an `SftpClient` (using SVN revision 41298, running with .NET Framework v4.5.1 on Windows Server 2012 R2).

I can reproduce the issue by connecting an `SftpClient` and then disposing it:

```
using (var sftp = new SftpClient(host, port, username,
new PrivateKeyFile(keyFile, passphrase)))
{
sftp.Connect();
}
```

The exception details are:

```
System.NullReferenceException: Object reference not set to an instance of an object.
at Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected) in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\Session.NET.cs:line 81
at Renci.SshNet.Session.get_IsConnected() in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\Session.cs:line 261
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message) in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\Session.cs:line 1103
at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message) in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\Session.cs:line 683
at Renci.SshNet.Session.Disconnect() in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\Session.cs:line 658
at Renci.SshNet.BaseClient.Disconnect() in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\BaseClient.cs:line 239
at Renci.SshNet.BaseClient.Dispose(Boolean disposing) in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\BaseClient.cs:line 334
at Renci.SshNet.SftpClient.Dispose(Boolean disposing) in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\SftpClient.cs:line 1805
at Renci.SshNet.BaseClient.Dispose() in d:\Development\Renci.SshNet\svn\Renci.SshClient\Renci.SshNet\BaseClient.cs:line 320
at UserQuery.Main()
```

The following trace messages are logged:

```
Thread 8: Initiating connect to 'host:port'.
Thread 8: Server version '2.0' on 'SSHD'.
Thread 3: ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
Thread 3: SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
Thread 3: SendMessage to server 'KeyExchangeDhGroupExchangeRequest': 'SSH_MSG_KEX_DH_GEX_REQUEST'.
Thread 3: ReceiveMessage from server: 'KeyExchangeDhGroupExchangeGroup': 'SSH_MSG_KEX_DH_GEX_GROUP'.
Thread 3: SendMessage to server 'KeyExchangeDhGroupExchangeInit': 'SSH_MSG_KEX_DH_GEX_INIT'.
Thread 3: ReceiveMessage from server: 'KeyExchangeDhGroupExchangeReply': 'SSH_MSG_KEX_DH_GEX_REPLY'.
Thread 3: SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
Thread 3: ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
Thread 8: SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
Thread 3: ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
Thread 8: SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
Thread 3: ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
Thread 8: SendMessage to server 'RequestMessagePublicKey': 'SSH_MSG_USERAUTH_REQUEST'.
Thread 3: ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
Thread 8: SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN'.
Thread 3: ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
Thread 8: SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
Thread 3: ReceiveMessage from server: 'ChannelWindowAdjustMessage': 'SSH_MSG_CHANNEL_WINDOW_ADJUST : #0'.
Thread 3: ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
Thread 8: SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
Thread 3: ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
Thread 8: SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
Thread 3: ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
> Dispose called here <
Thread 8: SendMessage to server 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
Thread 3: ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
Thread 8: SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
Thread 3: ReceiveMessage from server: 'DisconnectMessage': 'SSH_MSG_DISCONNECT'.
Thread 3: Disconnect received: ProtocolError Failed to read binary packet data!
```

Thread 8 is the thread that created the SftpClient. Thread 3 is the listener thread.

The `NullReferenceException` is raised because `_socket` is `null` when evaluating the `_socket.Available == 0` condition in `Session.IsSocketConnected()`. It appears that the `_socket.Poll` call on the previous line either causes or allows a `DisconnectMessage` from the server to be processed. The handler for the `DisconnectMessage` calls `Disconnect` again, which disconnects, disposes and assigns `_socket` to `null`.

Viewing all articles
Browse latest Browse all 1026

Trending Articles



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