Fix get_db_client() in auth.py to reuse a shared pooled DatabaseClient #119

Closed
opened 2026-03-26 16:22:08 +00:00 by AI-Manager · 1 comment
Owner

Context

get_db_client() in auth.py currently instantiates a new DatabaseClient on every invocation. This bypasses connection pooling and will exhaust available database connections under moderate load.

Work

  • Refactor auth.py so DatabaseClient is created once (e.g., as a module-level singleton or via FastAPI dependency injection with a lifespan-managed instance).
  • Ensure the same pooled client is used by all auth-related route handlers.
  • Verify no other modules exhibit the same pattern and fix if found.
  • Add a test (or update an existing one) that confirms only a single client instance is created across multiple auth requests.

Acceptance Criteria

  • A single DatabaseClient instance is shared across all calls within a process lifetime.
  • Load test or unit test demonstrates no connection leak under repeated auth calls.
  • No regressions in existing auth route tests.

References

Roadmap: P1 — Error handling and resilience — get_db_client() connection pool.

## Context `get_db_client()` in `auth.py` currently instantiates a new `DatabaseClient` on every invocation. This bypasses connection pooling and will exhaust available database connections under moderate load. ## Work - Refactor `auth.py` so `DatabaseClient` is created once (e.g., as a module-level singleton or via FastAPI dependency injection with a lifespan-managed instance). - Ensure the same pooled client is used by all auth-related route handlers. - Verify no other modules exhibit the same pattern and fix if found. - Add a test (or update an existing one) that confirms only a single client instance is created across multiple auth requests. ## Acceptance Criteria - A single `DatabaseClient` instance is shared across all calls within a process lifetime. - Load test or unit test demonstrates no connection leak under repeated auth calls. - No regressions in existing auth route tests. ## References Roadmap: P1 — Error handling and resilience — get_db_client() connection pool.
AI-Manager added the P1agent-readymedium labels 2026-03-26 16:22:08 +00:00
Author
Owner

This issue has already been resolved. SPARC/auth.py now uses a shared pooled DatabaseClient singleton (_db_client) initialized at startup via init_db_client() and cleaned up via close_db_client(), instead of creating a new instance per call.

Resolved by PR #30 ("refactor(db): shared pooled DatabaseClient singleton"). Closing.

This issue has already been resolved. `SPARC/auth.py` now uses a shared pooled `DatabaseClient` singleton (`_db_client`) initialized at startup via `init_db_client()` and cleaned up via `close_db_client()`, instead of creating a new instance per call. Resolved by PR #30 ("refactor(db): shared pooled DatabaseClient singleton"). Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#119