This project is read-only.

Exception on Disconnect

Jan 10, 2012 at 2:58 PM
Edited Jan 10, 2012 at 2:59 PM

Hi !

I get this Exception when disconnecting from a SFTP server :

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Renci.SshNet.dll

I'd like to know if this is normal ? The exception occurs in the Session.NET.cs file in the SocketRead method at line 71, on this call :

var receivedBytes = this._socket.Receive(buffer, offset + receivedTotal, length - receivedTotal, SocketFlags.None);

I know this occurs because the _socket has been closed, and with the debugger I can see that _socket == null, but is it normal that after we perform a Disconnect(), it stills tries to read something on the socket ?

Thank you.

EDIT: I use the last version of the lib, from the source.

Jan 10, 2012 at 3:17 PM



Yes, it is normal and I am trying to catch those error so it doesnt gets to the code but I guess sometimes it still does.

What happens, is while first thread issues disconect, it tells server to close the connection while second thread still reading it.

Once read operation detects socket was closed it throws this exception.

There should be some kind of reason code when SocketException is thrown, please not what reason are you getting and I will see if I can add this case to be handled so you dont get this execption thrown.


Hope it help,



Jan 17, 2012 at 1:15 PM
Edited Jan 17, 2012 at 1:16 PM

Hi !

Thank you for this explanation.

The reason given by the SocketException correspond to the error code : 10053 (WSAECONNABORTED)

with the message : 

Software caused connection abort.
An established connection was aborted by the software in your host computer, possibly due to a data transmission time-out or protocol error.

I got this from the Windows Socket Error page on MSDN :

Jan 17, 2012 at 2:59 PM

Well, this error is ok, since it indicates that connection was dropped by the server.


I will see if I can hide it somehow but as far as I remember you should get this exception only when server decides to terminate the connection.