logreader: skip internal source if connection refused (#32418)

* logreader: skip internal source if connection refused

* fix indentation

* fix spacing

* explicit ipv4 and tcp
This commit is contained in:
Greg Hogan
2024-05-13 16:02:28 -07:00
committed by GitHub
parent 7f9ad78ac8
commit 2a46d71fc8
+5 -4
View File
@@ -10,10 +10,11 @@ DATA_ENDPOINT = os.getenv("DATA_ENDPOINT", "http://data-raw.comma.internal/")
def internal_source_available():
try:
hostname = urlparse(DATA_ENDPOINT).hostname
if hostname:
socket.gethostbyname(hostname)
return True
except socket.gaierror:
port = urlparse(DATA_ENDPOINT).port or 80
with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
s.connect((hostname, port))
return True
except (socket.gaierror, ConnectionRefusedError):
pass
return False