fix: guard reserved sessions and bounded response state

This commit is contained in:
kiyo9w 2026-09-28 13:41:35 +09:00
parent 0e85c399bb
commit 745a29d979
3 changed files with 62 additions and 3 deletions

View file

@ -270,7 +270,8 @@ def create_app(
async def lifespan(_app: FastAPI):
yield
for session in list(sessions.values()):
session.close()
if session is not None:
session.close()
engine.shutdown()
app = FastAPI(
@ -1111,6 +1112,11 @@ def main() -> None:
LOGGER.info("Loading model and catalog (device=%s, imgsz=%s)...",
engine_settings.device or "auto", engine_settings.imgsz)
engine = build_default_engine(engine_settings)
if (engine_settings.identity_backend or "").lower() == "gallery":
if engine.identity_gallery() is None:
raise RuntimeError(
"gallery identity backend requires local DINOv2 weights; refusing to start"
)
warm_ms = engine.warm_up()
LOGGER.info(
"Ready: %d SKUs, catalog %s, warmup %.0f ms, classify workers %d",