fix: await background sync task cancellation in lifespan shutdown (#456)

Signed-off-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
This commit is contained in:
Paul Hernandez
2025-12-17 09:53:34 -06:00
committed by GitHub
parent a0f20eb102
commit efbc758325
2 changed files with 75 additions and 0 deletions
+5
View File
@@ -59,6 +59,7 @@ async def lifespan(app: FastAPI): # pragma: no cover
app.state.sync_task = asyncio.create_task(initialize_file_sync(app_config))
else:
logger.info("Sync changes disabled. Skipping file sync service.")
app.state.sync_task = None
# proceed with startup
yield
@@ -67,6 +68,10 @@ async def lifespan(app: FastAPI): # pragma: no cover
if app.state.sync_task:
logger.info("Stopping sync...")
app.state.sync_task.cancel() # pyright: ignore
try:
await app.state.sync_task
except asyncio.CancelledError:
logger.info("Sync task cancelled successfully")
await db.shutdown_db()