Fix get_db_client() in auth.py to use a shared connection pool #308

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

Context

Roadmap item: P1 Error handling and resilience

get_db_client() in auth.py instantiates a new DatabaseClient on every invocation. Under load this exhausts the PostgreSQL connection limit and causes request failures.

Work Required

  • Identify how DatabaseClient manages connections (asyncpg pool, psycopg2 pool, etc.)
  • Refactor get_db_client() to return a module-level singleton or a FastAPI dependency that shares a single pooled client across requests
  • Ensure the pool is initialised during app startup and closed during shutdown (use FastAPI lifespan or startup/shutdown events)
  • Remove any per-request DatabaseClient() constructor calls in auth.py

Acceptance Criteria

  • A load test (or manual inspection) confirms only one pool is created per process
  • All existing auth-related tests continue to pass
  • No new database connection errors appear in logs during concurrent requests
## Context Roadmap item: P1 Error handling and resilience `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every invocation. Under load this exhausts the PostgreSQL connection limit and causes request failures. ## Work Required - Identify how `DatabaseClient` manages connections (asyncpg pool, psycopg2 pool, etc.) - Refactor `get_db_client()` to return a module-level singleton or a FastAPI dependency that shares a single pooled client across requests - Ensure the pool is initialised during app startup and closed during shutdown (use FastAPI lifespan or startup/shutdown events) - Remove any per-request `DatabaseClient()` constructor calls in `auth.py` ## Acceptance Criteria - A load test (or manual inspection) confirms only one pool is created per process - All existing auth-related tests continue to pass - No new database connection errors appear in logs during concurrent requests
AI-Manager added the P1agent-readymedium labels 2026-03-27 12:22:35 +00:00
Author
Owner

This issue has already been resolved in the fork's main branch. Already implemented in PR #30 (refactor(db): shared pooled DatabaseClient singleton). See SPARC/database.py.

Closing as completed.

This issue has already been resolved in the fork's main branch. Already implemented in PR #30 (refactor(db): shared pooled DatabaseClient singleton). See SPARC/database.py. 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#308