Server timeout doesn't work with .NET Assembly

Advertisement

irina
Guest

Server timeout doesn't work with .NET Assembly

In our company we use .NET Assembly (winscpnet.dll) and WinScp utility to upload files on SFTP server. A connection with some of SFTP servers is very slow. So default 15 seconds connection timeout is not enough. We set different timeout in SessionOptions object and pass it to Session Open method, but it doesn't change the actual connection timeout (e.g. we set 5 mins timeout, call Open method and get timeout exception with message "Network error: Connection to [ip address] timed out." in about 15-20 seconds).

Open session call example:

 
  SessionOptions sessionOptions = new SessionOptions
  {
     Protocol = Protocol.Sftp,
     HostName = host,
     UserName = userName,
     Password = password,
     PortNumber = port,
     SshHostKeyFingerprint = hostKeyFingerPrint,
     Timeout = new TimeSpan(0, 5, 0)
  };

  _session.Open(sessionOptions);

In Log file we see that the following commands are executed and timeout parameter has the right value 300 seconds:

option batch on
option confirm off
option reconnecttime 120
open "sftp://username:***@10.11.178.20:22" -hostkey="ssh-ed25519 256 86:ff:cb:71:7a:e7:46:36:31:b2:26:01:a7:ec:a1:96" -timeout=300

Using WinSCP 5.11.1 on Windows 10 (also it is reproduced on Windows Server 2012 R2). Debug log file is attached.
  • TimeoutIssueLog.log (45.05 KB, Private file)
Description: Debug log file.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,507
Location:
Prague, Czechia

Re: Server timeout doesn't work with .NET Assembly

It's ultimately on the operating system how long it will keep waiting for the connection.

Wouldn't it help it you retry the connection immediately after the timeout?

Reply with quote

irina
Joined:
Posts:
2
Location:
Russia

Re: Server timeout doesn't work with .NET Assembly

Could you please clarify does it make sense to try to do it if we have persistent slow connection? E.g. the default server reponse timeout is 15 seconds, we retry connection immediately after the timeout and it works. Will we be able to upload files to a server if time to get a server response is more that 15 seconds?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,507
Location:
Prague, Czechia

Re: Server timeout doesn't work with .NET Assembly

Once you get connected, the SessionOptions.Timeout does apply unconditionally (contrary to connection timeout, where system may enforce its own timeout). So increasing it will help.

Reply with quote

irina
Joined:
Posts:
2
Location:
Russia

Re: Server timeout doesn't work with .NET Assembly

martin wrote:

It's ultimately on the operating system how long it will keep waiting for the connection.

Wouldn't it help it you retry the connection immediately after the timeout?

Seems that this solution doesn't work. I tested it in the following way:

1. Got timeout time between Session Open method call and timeout exception on my local machine. It is always was about 23000 ms.
2. In a network emulator tool set latency for full package trip 24000ms (also tried 26000, 28000, 30000).
3. In a code added addtional Session Open method call right after getting of timeout exception (I got timeout exception for this call again).

So could you please confirm that the test scenario described above is appropriate? If it is true, may be there is another way to fix this issue?

Thank you

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,507
Location:
Prague, Czechia

Re: Server timeout doesn't work with .NET Assembly

If the OS timeouts the connection before the server replies, then indeed no matter how many retries you do, it will never connect.
But I understood that your real server does not respond that late always, that's why I've suggested the retry.
Anyway, are you able to reliably connect using any other SSH/SFTP client?

Reply with quote

Advertisement

You can post new topics in this forum