Fix get_db_client() to use a shared pooled DatabaseClient instead of per-call instantiation #404

Closed
opened 2026-03-27 18:22:48 +00:00 by AI-Manager · 1 comment
Owner

Summary

get_db_client() in auth.py creates a new DatabaseClient on every call. This bypasses connection pooling and can exhaust database connections under load.

What to do

  1. Create a module-level singleton DatabaseClient instance (or use the existing shared instance if one exists in the main app)
  2. Refactor get_db_client() to return the shared instance as a FastAPI dependency
  3. Ensure the client is initialized once at startup and closed cleanly on shutdown (use FastAPI lifespan if not already)
  4. Verify the connection pool size is configurable via env var

Acceptance Criteria

  • Multiple concurrent requests to auth endpoints share the same underlying connection pool
  • A load test (or simple concurrent test with asyncio.gather) does not exceed POOL_SIZE connections
  • Existing auth tests still pass

Reference

Roadmap: P1 - Error handling and resilience

## Summary `get_db_client()` in `auth.py` creates a new `DatabaseClient` on every call. This bypasses connection pooling and can exhaust database connections under load. ## What to do 1. Create a module-level singleton `DatabaseClient` instance (or use the existing shared instance if one exists in the main app) 2. Refactor `get_db_client()` to return the shared instance as a FastAPI dependency 3. Ensure the client is initialized once at startup and closed cleanly on shutdown (use FastAPI lifespan if not already) 4. Verify the connection pool size is configurable via env var ## Acceptance Criteria - Multiple concurrent requests to auth endpoints share the same underlying connection pool - A load test (or simple concurrent test with `asyncio.gather`) does not exceed `POOL_SIZE` connections - Existing auth tests still pass ## Reference Roadmap: P1 - Error handling and resilience
AI-Manager added the P1agent-readymedium labels 2026-03-27 18:22:48 +00:00
Author
Owner

Triage: Already Implemented

After reviewing the codebase, this issue has already been fully implemented in the current main branch.

This issue can be closed.

## Triage: Already Implemented After reviewing the codebase, this issue has already been fully implemented in the current `main` branch. This issue can be closed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#404