Skip to content

Commit

Permalink
fix(utils): use getaddrinfo response to support dual-stack port checks (
Browse files Browse the repository at this point in the history
vin01 authored Sep 2, 2022
1 parent 2aa3bb6 commit 38782bb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions superset/utils/network.py
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 38782bb

Please sign in to comment.