From ecaad7c6bd63465330cd85663f65066c5fd4ae0c Mon Sep 17 00:00:00 2001 From: ciregenz Date: Fri, 19 Jun 2026 17:23:14 -0700 Subject: [PATCH] [eric] edge: degrade to not-found on any storage error, never 500 the whole edge --- openswarm-edge/app/bundles.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/openswarm-edge/app/bundles.py b/openswarm-edge/app/bundles.py index 652cf731..95fbb69a 100644 --- a/openswarm-edge/app/bundles.py +++ b/openswarm-edge/app/bundles.py @@ -6,6 +6,7 @@ from __future__ import annotations import asyncio import io +import logging import mimetypes import os import posixpath @@ -18,6 +19,8 @@ import boto3 from botocore.config import Config from botocore.exceptions import ClientError +logger = logging.getLogger(__name__) + _ENDPOINT = os.environ.get("TIGRIS_ENDPOINT", "https://fly.storage.tigris.dev") _BUCKET = os.environ.get("TIGRIS_BUCKET", "openswarm-apps") _TTL_SECONDS = int(os.environ.get("EDGE_BUNDLE_TTL_SECONDS", "120")) @@ -98,11 +101,22 @@ async def get_bundle(slug: str) -> Optional[Bundle]: raw = await asyncio.to_thread(obj["Body"].read) except ClientError as e: code = str(e.response.get("Error", {}).get("Code", "")) - if code in ("NoSuchKey", "404", "NoSuchBucket", "AccessDenied"): - _cache.pop(slug, None) - return None - raise - bundle = unpack(raw) + if code not in ("NoSuchKey", "404", "NoSuchBucket"): + # creds/permission/other storage error: log it but still degrade to a + # clean not-found rather than 500-ing every app on a storage hiccup. + logger.warning("tigris get failed for %s: %s", slug, code or e) + _cache.pop(slug, None) + return None + except Exception as e: + # missing creds, network, malformed bundle: never 500 the whole edge. + logger.warning("tigris get error for %s: %s", slug, e) + _cache.pop(slug, None) + return None + try: + bundle = unpack(raw) + except Exception as e: + logger.warning("bundle unpack failed for %s: %s", slug, e) + return None if len(_cache) >= _MAX_CACHED_BUNDLES: oldest = min(_cache, key=lambda k: _cache[k].fetched_at) _cache.pop(oldest, None)