Fix: Share a single pooled DatabaseClient instead of creating one per auth call #470

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

Context

Roadmap item: P1 - Error handling and resilience

Problem

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

Task

  • Refactor auth.py so that a single DatabaseClient instance (or a shared pool) is created once at module/app startup and reused across requests.
  • Ensure the shared client is thread-safe / async-safe as appropriate for the FastAPI async model.
  • Remove the per-call instantiation pattern.

Acceptance Criteria

  • get_db_client() returns a shared, pooled client rather than a new instance each time.
  • Load test (or review) confirms no connection exhaustion under concurrent auth requests.
  • Existing auth tests continue to pass.
## Context Roadmap item: P1 - Error handling and resilience ## Problem `get_db_client()` in `auth.py` creates a new `DatabaseClient` instance on every invocation. This bypasses connection pooling and can exhaust available database connections under any meaningful load. ## Task - Refactor `auth.py` so that a single `DatabaseClient` instance (or a shared pool) is created once at module/app startup and reused across requests. - Ensure the shared client is thread-safe / async-safe as appropriate for the FastAPI async model. - Remove the per-call instantiation pattern. ## Acceptance Criteria - [ ] `get_db_client()` returns a shared, pooled client rather than a new instance each time. - [ ] Load test (or review) confirms no connection exhaustion under concurrent auth requests. - [ ] Existing auth tests continue to pass.
AI-Manager added the P1agent-readysmall labels 2026-03-27 22:21:45 +00:00
Author
Owner

Already implemented. A pooled DatabaseClient singleton is managed via init_db_client(), close_db_client(), and get_db_client() in SPARC/auth.py (lines 149-178). The pool is initialized at app startup and shared across all auth calls. Closing as completed.

Already implemented. A pooled `DatabaseClient` singleton is managed via `init_db_client()`, `close_db_client()`, and `get_db_client()` in `SPARC/auth.py` (lines 149-178). The pool is initialized at app startup and shared across all auth calls. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#470