From 7a9b709a6c649b3900f4eed0e855ef1541dbd642 Mon Sep 17 00:00:00 2001 From: Anas Sulaiman Date: Tue, 14 Nov 2023 03:43:15 +0000 Subject: [PATCH] avoid unnecessary failures in get_hostname The catch clause was specific to one error type, but other errors may also happen such as socket.herror. In any case, the point is to fallback anyways. Bug: b/310216577 Change-Id: I55561f8f40446f90bee27ea2aab1a4e60c03e7e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5024019 Reviewed-by: Junji Watanabe Commit-Queue: Anas Sulaiman Reviewed-by: Michael Savigny --- reclient_helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reclient_helper.py b/reclient_helper.py index ddeb403c57..2b99707e61 100644 --- a/reclient_helper.py +++ b/reclient_helper.py @@ -125,7 +125,10 @@ def get_hostname(): hostname = socket.gethostname() try: return socket.gethostbyaddr(hostname)[0] - except socket.gaierror: + except Exception as e: + print("socket.gethostbyaddr failed " + + "(falling back to socket.gethostname): %s" % e, + file=sys.stderr) return hostname