ParallelSSH / ssh2-python

Python bindings for libssh2 C library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
228 stars 70 forks source link

session.handshake(socket) hanging for at least 5 minutes #109

Closed hakaishi closed 3 years ago

hakaishi commented 3 years ago

An error is raised immediately when the port is not available, but if I use a port that is not used for ssh it will hang for 5 minutes. My system runs vsftp, so port 21 is open. I tried the following:

sock = socket(AF_INET, SOCK_STREAM)
sock.settimeout(3)
sock.connect(("localhost", 21))
sock.settimeout(3)
cli = Session()
cli.handshake(sock)

cli.userauth_password("name", "password")

Result: The code will hang for 5 minutes at cli.handshake(sock) I would expect to be able to set an reasonable timeout until an error is raised. For example 10 seconds. I can't let the user to wait 5 minutes until he gets the feedback that the port is wrong.

pkittenis commented 3 years ago

Libssh2 has it's own timeout that needs setting.

See Session.set_timeout

hakaishi commented 3 years ago

Omg! So there was one and I overlooked it. Sorry 😥