0 votes
by (240 points)

I have explicitly set the Sftp.Timeout property to 60 seconds, yet when I attempt to connect to an SFTP site, the connection times out after 20 seconds (actually a hair over 21 seconds), examining the timestamps.

There is a real SFTP site that I need to connect to that responds slowly at times. The 20 second timeout is often not long enough to establish the initial connection, though sometimes it barely manages to work.

Here is a log of trying to connect to an SFTP site that does not exist (just to demonstrate the Sftp.Timeout property being ignored):

2019-08-29 15:57:59.193 INFO Sftp(1) Info: Connecting to 192.168.3.33:22 using Sftp.
2019-08-29 15:57:59.195 INFO Sftp(1) Info: Assembly: Rebex.Sftp 2019 R3 for .NET 4.6-4.8
2019-08-29 15:57:59.197 INFO Sftp(1) Info: Platform: Windows 6.2.9200 32-bit; CLR: 4.0.30319.42000
2019-08-29 15:57:59.198 DEBUG Sftp(1) Info: Culture: en; Windows-1252
2019-08-29 15:58:20.232 ERROR Sftp(1) Info: Rebex.Net.ProxySocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.3.33:22
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at ciqf.Connect(EndPoint remoteEP)
   at ciqi.mfai(IPEndPoint jp)
   at ciqk.oiyr(EndPoint bju)
   at Rebex.Net.ProxySocket.Connect(EndPoint remoteEP)
   --- End of inner exception stack trace ---
   at Rebex.Net.ProxySocket.Connect(EndPoint remoteEP)
   at Rebex.Net.ProxySocket.Connect(String serverName, Int32 serverPort)
   at Rebex.Net.Sftp.dvjm(String po, Int32 pp, SshParameters pq, valv pr)

Is there another setting that controls the timeout on the initial SFTP connection, or is this a bug that needs to be fixed?

I appreciate any help pointing me in the right direction!

Applies to: Rebex SFTP

1 Answer

0 votes
by (147k points)

According to the log, it was .NET's System.Net.Sockets.Socket object's Connect method that failed after 21 seconds. Our Sftp.Timeout specifies the maximum duration of the Connect operation and ensures it's aborted when the specified timeout expires, but it does not (and unfortunately cannot) prevent the operation from failing sooner. This means that Sftp.Timeout is actually behaving as expected. Applications cannot override the behavior of the underlying operating system's TCP subsystem, which is where this issue comes from. To increase its timeout, you have to tweak Windows TCP/IP settings:

Set-NetTCPSetting -SettingName InternetCustom -MaxSynRetransmissions 4

The following code should reproduce the problem without using any Rebex code:

var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var ep = new IPEndPoint(IPAddress.Parse("192.168.3.33"), 22);
socket.Connect(ep);

For more information about this and for details on how to tweak the Windows TCP/IP setting, please see the following:
- Increase timeout for System.Net.Sockets.Socket connect on stackoverflow.com
- How to set TCP/IP abort interval or timeout on superuser.com

...