2

I'm trying to get Python paramiko timeout on connect(). It works for many hosts but with one in particular, it just never timeout. Here is my code :

# python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20)
...
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect(hostname="10.68.45.210", username="root", password="a_none_working_pass", timeout=2)

^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/paramiko/client.py", line 307, in connect
    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
  File "/usr/lib/python3/dist-packages/paramiko/client.py", line 510, in _auth
    self._transport.auth_password(username, password)
  File "/usr/lib/python3/dist-packages/paramiko/transport.py", line 1166, in auth_password
    return self.auth_handler.wait_for_response(my_event)
  File "/usr/lib/python3/dist-packages/paramiko/auth_handler.py", line 192, in wait_for_response
    event.wait(0.1)
  File "/usr/lib/python3.4/threading.py", line 553, in wait
    signaled = self._cond.wait(timeout)
  File "/usr/lib/python3.4/threading.py", line 294, in wait
    gotit = waiter.acquire(True, timeout)
KeyboardInterrupt

What am I doing wrong?

I've done an strace of the process and when it hangs, I obtain these messages in loop:

select(0, NULL, NULL, NULL, {0, 1000})  = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 2000})  = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 4000})  = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 8000})  = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 16000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 32000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 36139}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 1000})  = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 2000})  = 0 (Timeout)

Tried on Debian Jessie with Python 2.7.3 and 3.4.2 and both hangs in an infinite loop.

EDIT: Seems to be related with this SO topic: Why does Paramiko hang if you use it while loading a module? but is there a way to shelve of this issue?

Community
  • 1
  • 1
gr0bz
  • 189
  • 1
  • 2
  • 11
  • Do you know the port of the server you are trying to access? –  Sep 03 '15 at 17:22
  • 22, to be original ;) – gr0bz Sep 15 '15 at 12:21
  • is this always reproducible? can you provide a testcase (server response, pcap)? I see the same issue with the timed busy-wait in `self.auth_handler.wait_for_response(my_event)` but cannot reliably reproduce it in order to debug it. Anyway, the problem is that the `my_event` that is set with `self.auth_handler.auth_password(username, password, my_event)` never happens. I suspect that this happens when paramiko receives no response to the auth_request for the transport. – tintin Sep 30 '15 at 21:42

1 Answers1

1

I had the same timeout hanging issue with Paramiko connect, the solution that worked for me was to update Paramiko to the latest version that supports auth_timeout.

session.connect('ipAddress', username='username', pkey=key, timeout=5, banner_timeout=5, auth_timeout=5)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
iron3rd
  • 49
  • 2
  • 6