Refactor get_db_client() in auth.py to use a shared pooled connection #1595

Closed
opened 2026-04-19 23:23:53 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Error handling and resilience

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

What to do

  • Refactor get_db_client() to return a shared singleton or use FastAPI dependency injection with a properly pooled client
  • Ensure the pooled client is initialized once at application startup
  • Close the pool gracefully on application shutdown (lifespan handler)

Acceptance criteria

  • A single pooled DatabaseClient is shared across all auth requests
  • No new DatabaseClient is instantiated per request in auth.py
  • Connection pool is closed on shutdown
  • Existing auth tests continue to pass

Ref: ROADMAP.md P1 - Error handling and resilience

## Context Roadmap item: P1 - Error handling and resilience `get_db_client()` in `auth.py` creates a new `DatabaseClient` on every call. This bypasses the connection pool and can exhaust database connections under load. ## What to do - Refactor `get_db_client()` to return a shared singleton or use FastAPI dependency injection with a properly pooled client - Ensure the pooled client is initialized once at application startup - Close the pool gracefully on application shutdown (lifespan handler) ## Acceptance criteria - [ ] A single pooled `DatabaseClient` is shared across all auth requests - [ ] No new `DatabaseClient` is instantiated per request in `auth.py` - [ ] Connection pool is closed on shutdown - [ ] Existing auth tests continue to pass Ref: ROADMAP.md P1 - Error handling and resilience
AI-Manager added the P1agent-readysmallrefactor labels 2026-04-19 23:23:53 +00:00
Author
Owner

This issue is already resolved in main. auth.py uses a module-level singleton _db_client initialized via init_db_client() at startup and accessed via get_db_client(). The DatabaseClient itself uses connection pooling internally.

This issue is already resolved in main. `auth.py` uses a module-level singleton `_db_client` initialized via `init_db_client()` at startup and accessed via `get_db_client()`. The `DatabaseClient` itself uses connection pooling internally.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1595