Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions distributed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,23 @@ def get_fileno_limit():
@toolz.memoize
def _get_ip(host, port, family):
def hostname_fallback():
addr_info = socket.getaddrinfo(
socket.gethostname(), port, family, socket.SOCK_DGRAM, socket.IPPROTO_UDP
)[0]
return addr_info[4][0]
try:
addr_info = socket.getaddrinfo(
socket.gethostname(),
port,
family,
socket.SOCK_DGRAM,
socket.IPPROTO_UDP,
)[0]
return addr_info[4][0]
# If getaddrinfo() fails, relay the error and return a sane default
except socket.gaierror as e:
warnings.warn(
f"Couldn't detect a suitable IP address ({e}). "
"Falling back to 127.0.0.1.",
RuntimeWarning,
)
return "127.0.0.1"

# By using a UDP socket, we don't actually try to connect but
# simply select the local address through which *host* is reachable.
Expand Down
Loading