From 6dff1dc294291d4171cb0dcf61847a7237618e69 Mon Sep 17 00:00:00 2001 From: Tao He Date: Mon, 5 Sep 2022 20:17:55 +0800 Subject: [PATCH] Use a `getaddrinfo` resolvable hostname as the local hostname (will be used as the etcd endpoint further). (#2006) Signed-off-by: Tao He --- coordinator/gscoordinator/launcher.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/coordinator/gscoordinator/launcher.py b/coordinator/gscoordinator/launcher.py index e8038888d42f..98bdcdd6580c 100644 --- a/coordinator/gscoordinator/launcher.py +++ b/coordinator/gscoordinator/launcher.py @@ -357,8 +357,15 @@ def _launch_etcd(self): else: self._etcd_peer_port = get_free_port() if len(self._hosts) > 1: + try: + local_hostname = socket.gethostname() + socket.gethostbyname( + local_hostname + ) # make sure the hostname is dns-resolvable + except Exception: + local_hostname = "127.0.0.1" # fallback to a must-correct hostname self._etcd_endpoint = "http://{0}:{1}".format( - socket.gethostname(), str(self._etcd_client_port) + local_hostname, str(self._etcd_client_port) ) else: self._etcd_endpoint = "http://127.0.0.1:{0}".format(