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

Commented Unassigned: Sftpclient.Disconnect takes very long time [2738]

$
0
0
The following code takes over two minutes to execute. It gets stuck on Disconnect(). I am trying to connect to TITAN commercial FTP Server.


SftpClient client = new SftpClient(sAddress, iPort, sUserID, password);
client.Connect();
client.Disconnect();

I can connect to other SFTP sites just fine.

Any idea what would be wrong?

-Jayesh
Comments: ** Comment from web user: mahowling **

I was also getting an issue where the disconnect from a WingFTP server wasn't responding. Whilst comparing the SshNet logging to another SFTP site I noticed this appearing after the Receive message for ChannelCloseMessage:

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

I tracked that back to the SocketRead method in Session.Net.cs. I can only assume that the FTP is disconnecting so quickly it's causing an issue with reading the result (or there just isn't a result).

The catch block in this message attempts to Disconnect if there is a ConnectionAbort, but we are already in the disconnect process. I think this causes an issue with the subsequent closing of the connection.

I think I've managed to solve it (at least for me). I modified the SocketException Catch in Session.Net.cs SocketRead to perform a check on the _isDisconnecting flag.

```
catch (SocketException exp)
{
if (exp.SocketErrorCode == SocketError.ConnectionAborted)
{
buffer = new byte[length];
if (!_isDisconnecting) Disconnect();
return;
}

if (exp.SocketErrorCode == SocketError.WouldBlock ||
exp.SocketErrorCode == SocketError.IOPending ||
exp.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
{
// socket buffer is probably empty, wait and try again
Thread.Sleep(30);
}
else
throw; // any serious error occurred
}
```


Viewing all articles
Browse latest Browse all 1026

Trending Articles