sshtools / maverick-synergy

Next Generation Java SSH API
https://jadaptive.com
GNU Lesser General Public License v3.0
96 stars 26 forks source link

Connection timeout not respected/too long #98

Closed dijanavv closed 1 week ago

dijanavv commented 1 month ago

We set connection timeout to 10 seconds but in reality is timing out every time after 2+ minutes. Using maverick-synergy-client:3.0.11 2024-10-02 04:16:27,212 | before sftp connect... 2024-10-02 04:18:36,145 | FTPConnectionException: Connection timed out

With earlier versions, original j2ssh or j2ssh-maverick:1.5.5 that was working fine, why is not this time? It is true sftp host trying to connect is down, but still not good to timeout after so long time. Is this known issue?

dijanavv commented 1 month ago

From what I can see even your latest 3.1.x version does not set socket SoTimeout only this: socketChannel.socket().setTcpNoDelay(true);

while with j2ssh-maverick it was exposed to us to set it like this: SocketTransport st = new SocketTransport(hostname, port); st.setTcpNoDelay(true); st.setSoTimeout(connectTimeout);

Would you be able to add this improvement to maverick-synergy-client? It is easy to reproduce, just sftp connect to some server which is down.

ludup commented 1 month ago

The code you are referencing in the older API is for a socket timeout, not connect timeout.

I can confirm that connect timeout is not working currently.

Socket timeouts (timeout once the connection has been established) are handled internally and should not be changed. If you want to ensure a connection is disconnected after a specific time of idle use the SshContext setIdleConnectionTimeoutSeconds method to set a reasonable timeout.

ludup commented 1 month ago

This should be fixed now in 3.2.0-SNAPSHOT on the develop branch.