You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SshClient.connect() - not failing over IPv6 to IPv4 when IPv6 address is unreachable. #686
Paramiko tries the IPv6 address first (hangs for couple of minutes) and then times out. No fail over to IPv4 occurs. Output below.
Additionally when specifying hostname as the IPv4 address, the connection is instantly successful.
Exception raised:
client.connect(hostname=hostname, username=username, password=password, allow_agent=False)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 292, in connect
retry_on_signal(lambda: sock.connect(addr))
File "/usr/local/lib/python2.7/dist-packages/paramiko/util.py", line 270, in retry_on_signal
return function()
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 292, in
retry_on_signal(lambda: sock.connect(addr))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 110] Connection timed out
This may be a bug in the connection code, which is supposed to try all possible versions of the requested address in order, optionally with an explicit timeout (which you can pass to .connect()). See
# Raise anything that isn't a straight up connection error
# (such as a resolution error)
ife.errnonotin (ECONNREFUSED, EHOSTUNREACH):
raise
# Capture anything else so we know how the run looks once
# iteration is complete. Retain info about which attempt
# this was.
errors[addr] =e
which is the relevant code snippet.
Going by the Python stdlib docs for getaddrinfo, IPv4 probably pops up before IPv6 most of the time, which would be why it's tried first and is then gumming up the works.
At a glance, I'm thinking that this code was never actually tried in the "IPv4 times out, instead of being outright unreachable/unroutable" scenario, since the exception handling only skips unreachable/unconnectable errors - not timeouts. The fix may thus be as simple as updating that except line.
So either @gwtp needs to be comfortable testing a PR, or I (or another contributor) need to find/create a reproducible network case triggering this.
Had this same issue when using paramiko 2.4. I could .connect() fine when the host resolved to a single IPv4 address, but if it also had an IPv6 address associated I got a timeout error.
Had to use socket.gethostbyname(myhostname) as a workaround when connecting.
Activity
bitprophet commentedon Jul 2, 2016
Thanks for the report!
This may be a bug in the connection code, which is supposed to try all possible versions of the requested address in order, optionally with an explicit timeout (which you can pass to
.connect()). Seeparamiko/paramiko/client.py
Lines 296 to 316 in 0ae019c
Going by the Python stdlib docs for
getaddrinfo, IPv4 probably pops up before IPv6 most of the time, which would be why it's tried first and is then gumming up the works.At a glance, I'm thinking that this code was never actually tried in the "IPv4 times out, instead of being outright unreachable/unroutable" scenario, since the exception handling only skips unreachable/unconnectable errors - not timeouts. The fix may thus be as simple as updating that
exceptline.So either @gwtp needs to be comfortable testing a PR, or I (or another contributor) need to find/create a reproducible network case triggering this.
Poply commentedon Nov 15, 2017
Had this same issue when using paramiko 2.4. I could
.connect()fine when the host resolved to a single IPv4 address, but if it also had an IPv6 address associated I got a timeout error.Had to use
socket.gethostbyname(myhostname)as a workaround when connecting.wsw70 commentedon Jun 28, 2024
The problem is still present in 3.4.0.
@Poply workaround to use
hostname=socket.gethostbyname(myhostname)works.