mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 22:43:00 +00:00
IPv6 ready hosts file localhost issue
This is to resolve the 'Network is Unreachable' error experienced by a few when JupyterHUB is connecting to localhost. On most recent linux OS versions like CentOS 6, 7, Red Hat 6, 7, Oracle Linux 6, 7, etc, the hosts file (/etc/hosts) usually has a line to make the server IPv6-ready: ::1 localhost even if the given server actually has no IPv6 permissioned. In such case the Python socket library when connecting to 'localhost' will try to connect via the IPv6 protocol - which will fail with the 'Network is Unreachable' error. To solve this we capture this error and try to reconnect on 127.0.0.1 instead of localhost, alias forcing the user of the IPv4 protocol.
This commit is contained in:
@@ -116,7 +116,17 @@ class Server(Base):
|
||||
try:
|
||||
socket.create_connection((self.ip or 'localhost', self.port))
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNREFUSED:
|
||||
if e.errno == errno.ENETUNREACH:
|
||||
try:
|
||||
socket.create_connection((self.ip or '127.0.0.1', self.port))
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNREFUSED:
|
||||
return False
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
return True
|
||||
elif e.errno == errno.ECONNREFUSED:
|
||||
return False
|
||||
else:
|
||||
raise
|
||||
|
Reference in New Issue
Block a user