diff --git a/src/server/fastapi_app.py b/src/server/fastapi_app.py index 0988629..36267ad 100644 --- a/src/server/fastapi_app.py +++ b/src/server/fastapi_app.py @@ -100,6 +100,18 @@ async def lifespan(app: FastAPI): # Shutdown logger.info("FastAPI application shutting down") + + # Shutdown download service and its thread pool + try: + from src.server.services.download_service import _download_service_instance + if _download_service_instance is not None: + logger.info("Stopping download service...") + await _download_service_instance.stop() + logger.info("Download service stopped successfully") + except Exception as e: + logger.error("Error stopping download service: %s", e, exc_info=True) + + logger.info("FastAPI application shutdown complete") # Initialize FastAPI app with lifespan