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

* logreader: skip internal source if connection refused

* fix indentation

* fix spacing

* explicit ipv4 and tcp
old-commit-hash: 2a46d71fc885201d88ca63bc52d26ef715545a23
This commit is contained in:
Greg Hogan
2024-05-13 16:02:28 -07:00
committed by GitHub
parent d71879a4af
commit a17639bddb
+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