Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Connectivity errors crashed the endpoint #529

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/aleph/vm/orchestrator/views/host_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ async def wrapper(*args: Any, **kwargs: Any) -> bool:
async def check_ip_connectivity(url: str, socket_family: socket.AddressFamily = socket.AF_UNSPEC) -> bool:
timeout = aiohttp.ClientTimeout(total=5)
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(family=socket_family), timeout=timeout) as session:
async with session.get(url) as resp:
# We expect the Quad9 endpoints to return a 404 error, but other endpoints may return a 200
if resp.status not in (200, 404):
resp.raise_for_status()
return True
try:
async with session.get(url) as resp:
# We expect the Quad9 endpoints to return a 404 error, but other endpoints may return a 200
if resp.status not in (200, 404):
resp.raise_for_status()
return True
except aiohttp.ClientConnectorError:
return False


@return_false_on_timeout
Expand Down
Loading