The function get_node_ip_address while catch an exception and return … (#2722)

…'127.0.0.1',

when we forbid the external network. Instead of we can get ip address from hostname.

The function get_node_ip_address while catch an exception and return '127.0.0.1' when we forbid the external network. Instead of we can get ip address from hostname.

https://github.com/ray-project/ray/issues/2721
This commit is contained in:
adoda 2018-08-28 13:24:49 +08:00 committed by Robert Nishihara
parent b4cba9a49f
commit 90ae8f11df

View file

@ -246,6 +246,14 @@ def get_node_ip_address(address="8.8.8.8:53"):
node_ip_address = s.getsockname()[0]
except Exception as e:
node_ip_address = "127.0.0.1"
# [Errno 101] Network is unreachable
if e.errno == 101:
try:
# try get node ip address from host name
host_name = socket.getfqdn(socket.gethostname())
node_ip_address = socket.gethostbyname(host_name)
except Exception:
pass
return node_ip_address