refactor: defensive getattr guard and clarified cleanup comment in lifespan

- Use getattr(app.state, 'federation_client', None) in shutdown to guard
  against the theoretical case where AsyncClient constructor raised before
  setting app.state.federation_client
- Rename 'Shutdown:' comment to 'Cleanup:' in the finally block to better
  describe that the block covers both the poll-task cancellation and the
  overall cleanup guarantee
This commit is contained in:
Brian Krabach
2026-04-01 14:13:45 -07:00
parent 43cc75efc8
commit 489a127056
+4 -2
View File
@@ -183,11 +183,13 @@ async def lifespan(app: FastAPI):
yield
try:
await app.state.federation_client.aclose()
client = getattr(app.state, "federation_client", None)
if client is not None:
await client.aclose()
except Exception:
_log.exception("federation_client aclose error")
finally:
# Shutdown: cancel the poll loop task and wait for it to finish.
# Cleanup: cancel the poll loop task and wait for it to finish.
if _poll_task is not None:
_poll_task.cancel()
try: