mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +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:
@@ -115,6 +115,10 @@ class Server(Base):
|
|||||||
"""Is the server accepting connections?"""
|
"""Is the server accepting connections?"""
|
||||||
try:
|
try:
|
||||||
socket.create_connection((self.ip or 'localhost', self.port))
|
socket.create_connection((self.ip or 'localhost', self.port))
|
||||||
|
except socket.error as e:
|
||||||
|
if e.errno == errno.ENETUNREACH:
|
||||||
|
try:
|
||||||
|
socket.create_connection((self.ip or '127.0.0.1', self.port))
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.errno == errno.ECONNREFUSED:
|
if e.errno == errno.ECONNREFUSED:
|
||||||
return False
|
return False
|
||||||
@@ -122,6 +126,12 @@ class Server(Base):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
elif e.errno == errno.ECONNREFUSED:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Proxy(Base):
|
class Proxy(Base):
|
||||||
|
Reference in New Issue
Block a user