This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 38782bb98a fix(utils): use getaddrinfo response to support dual-stack 
port checks (#21043)
38782bb98a is described below

commit 38782bb98aa1ca85ef97c73ce9b7dea658ee047e
Author: vin01 <[email protected]>
AuthorDate: Fri Sep 2 01:28:02 2022 +0000

    fix(utils): use getaddrinfo response to support dual-stack port checks 
(#21043)
---
 superset/utils/network.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/superset/utils/network.py b/superset/utils/network.py
index 8ae08d2c01..7a1aea5a71 100644
--- a/superset/utils/network.py
+++ b/superset/utils/network.py
@@ -27,16 +27,19 @@ def is_port_open(host: str, port: int) -> bool:
     Test if a given port in a host is open.
     """
     # pylint: disable=invalid-name
-    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    s.settimeout(PORT_TIMEOUT)
-    try:
-        s.connect((host, port))
-        s.shutdown(socket.SHUT_RDWR)
-        return True
-    except socket.error:
-        return False
-    finally:
-        s.close()
+    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
+        af, _, _, _, sockaddr = res
+        s = socket.socket(af, socket.SOCK_STREAM)
+        try:
+            s.settimeout(PORT_TIMEOUT)
+            s.connect((sockaddr))
+            s.shutdown(socket.SHUT_RDWR)
+            return True
+        except socket.error as _:
+            continue
+        finally:
+            s.close()
+    return False
 
 
 def is_hostname_valid(host: str) -> bool:

Reply via email to