SshSession timeout not working

0 votes
asked May 15, 2016 by marilynmhugon1080 (150 points)
edited May 16, 2016 by Tomas Knopp


I'm trying your component. And I see have problem with SshSession timeout. I tried set timeout = 1000 ms (=1s) or 100000 ms(=100s) but it's not working, seem that it only connect with default timeout is 60s. Please fix it

var session = new SshSession();

session.Timeout = 1000;
session.Authenticate(UserName, Password);

1 Answer

0 votes
answered May 16, 2016 by Lukas Pokorny (128,250 points)
edited Jul 1, 2016 by Lukas Pokorny
Best answer

Update: This has been fixed in version 2016 R2 of Rebex SFTP and Rebex Terminal Emulation.

Hi, thanks for letting us know about this problem. We will fix it for the next release.

In the meantime, you can use the following workaround:

int timeout = 1000;

var socket = new ProxySocket();
var ar = socket.BeginConnect(IPAddress, 22, null, null);
if (!ar.AsyncWaitHandle.WaitOne(timeout))
    throw new ProxySocketException("Operation timed out.", ProxySocketExceptionStatus.Timeout);

var session = new SshSession(socket);
session.Timeout = timeout;
session.Authenticate(UserName, Password);
commented May 17, 2016 by marilynmhugon1080 (150 points)
Thank you. I tried and it work with small timeout (eg int timeout = 1000, it will show excaption Operation timed out.). But when I set high timout, eg timeout = 100000, it will timeout after 30s only, not wait with full timeout that I set. Please check and fix
commented May 17, 2016 by Lukas Pokorny (128,250 points)
What exception message do you get when it times out after 30 seconds? It's quite possible this is the correct behavior. The Timeout property is used to specify the maximum acceptable duration of the operation, but it does not prevent the internals from failing sooner. This is actually quite common - some values (such as connection timeouts for TCP sockets) can't be controlled by applications, which means we can't make the TCP connection attempts fail later.
commented May 17, 2016 by marilynmhugon1080 (150 points)
I received the message exception "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." Please check
commented May 17, 2016 by Lukas Pokorny (128,250 points)
Thanks. This is actually an example of a failure that can't be postponed without changing system-wide TCP subsystem settings. Simply said, an application can't make TCP socket connection attempt last longer. The following .NET code demonstrates the same behavior:
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect("", 22);
Note that there is no Socket option that could be used to make the connection attempt last longer. The same applies to our components which use .NET Socket class internally.