From 90ae8f11df178f56f39980e7a97eb96c5e4c2124 Mon Sep 17 00:00:00 2001 From: adoda <35217964+adoda@users.noreply.github.com> Date: Tue, 28 Aug 2018 13:24:49 +0800 Subject: [PATCH] =?UTF-8?q?The=20function=20get=5Fnode=5Fip=5Faddress=20wh?= =?UTF-8?q?ile=20catch=20an=20exception=20and=20return=20=E2=80=A6=20(#272?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …'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 --- python/ray/services.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/ray/services.py b/python/ray/services.py index 0850441ff..725ff2bec 100644 --- a/python/ray/services.py +++ b/python/ray/services.py @@ -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