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: Status check fastapi view could crash due to ServerDisconnectedError. #537

Merged
merged 1 commit into from
Feb 14, 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
45 changes: 25 additions & 20 deletions src/aleph/vm/orchestrator/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,33 @@ async def status_check_fastapi(request: web.Request, vm_id: Optional[ItemHash] =
# Default to the value in the settings.
fastapi_vm_id: ItemHash = vm_id or ItemHash(settings.CHECK_FASTAPI_VM_ID)

async with aiohttp.ClientSession() as session:
result = {
"index": await status.check_index(session, fastapi_vm_id),
"environ": await status.check_environ(session, fastapi_vm_id),
"messages": await status.check_messages(session, fastapi_vm_id),
"dns": await status.check_dns(session, fastapi_vm_id),
"ipv4": await status.check_ipv4(session, fastapi_vm_id),
"internet": await status.check_internet(session, fastapi_vm_id),
"cache": await status.check_cache(session, fastapi_vm_id),
"persistent_storage": await status.check_persistent_storage(session, fastapi_vm_id),
"error_handling": await status.check_error_raised(session, fastapi_vm_id),
}
if not retro_compatibility:
# These fields were added in the runtime running Debian 12.
result = result | {
"lifespan": await status.check_lifespan(session, fastapi_vm_id),
# IPv6 requires extra work from node operators and is not required yet.
# "ipv6": await status.check_ipv6(session),
try:
async with aiohttp.ClientSession() as session:
result = {
"index": await status.check_index(session, fastapi_vm_id),
"environ": await status.check_environ(session, fastapi_vm_id),
"messages": await status.check_messages(session, fastapi_vm_id),
"dns": await status.check_dns(session, fastapi_vm_id),
"ipv4": await status.check_ipv4(session, fastapi_vm_id),
"internet": await status.check_internet(session, fastapi_vm_id),
"cache": await status.check_cache(session, fastapi_vm_id),
"persistent_storage": await status.check_persistent_storage(session, fastapi_vm_id),
"error_handling": await status.check_error_raised(session, fastapi_vm_id),
}

if not retro_compatibility:
# These fields were added in the runtime running Debian 12.
result = result | {
"lifespan": await status.check_lifespan(session, fastapi_vm_id),
# IPv6 requires extra work from node operators and is not required yet.
# "ipv6": await status.check_ipv6(session),
}

return web.json_response(
result, status=200 if all(result.values()) else 503, headers={"Access-Control-Allow-Origin": "*"}
)
except aiohttp.ServerDisconnectedError as error:
return web.json_response(
result, status=200 if all(result.values()) else 503, headers={"Access-Control-Allow-Origin": "*"}
{"error": f"Server disconnected: {error}"}, status=503, headers={"Access-Control-Allow-Origin": "*"}
)


Expand Down
Loading