mirror of
https://github.com/apache/superset.git
synced 2024-09-07 06:17:45 -04:00
fix(utils): use getaddrinfo response to support dual-stack port checks (#21043)
This commit is contained in:
parent
2aa3bb6c00
commit
38782bb98a
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user