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

Closed
opened 2026-03-29 22:22:29 +00:00 by AI-Manager · 2 comments
Owner

Background

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

What to do

  • Identify how DatabaseClient is instantiated and pooled elsewhere in the application (e.g., in the main app lifespan or a dependency).
  • Refactor get_db_client() (or replace it with a FastAPI dependency) so that auth routes receive the same shared, pooled client.
  • Remove any per-request client instantiation in auth.py.

Acceptance criteria

  • A single DatabaseClient instance (or pool) is shared across all routes including auth routes.
  • All existing tests pass.
  • Under a basic load test (e.g., 20 concurrent login requests) no too many connections error is raised.

Roadmap ref: ROADMAP.md — P1 / Error handling and resilience

## Background `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every call. This bypasses connection pooling and can exhaust available database connections under concurrent load. ## What to do - Identify how `DatabaseClient` is instantiated and pooled elsewhere in the application (e.g., in the main app lifespan or a dependency). - Refactor `get_db_client()` (or replace it with a FastAPI dependency) so that auth routes receive the same shared, pooled client. - Remove any per-request client instantiation in `auth.py`. ## Acceptance criteria - A single `DatabaseClient` instance (or pool) is shared across all routes including auth routes. - All existing tests pass. - Under a basic load test (e.g., 20 concurrent login requests) no `too many connections` error is raised. Roadmap ref: ROADMAP.md — P1 / Error handling and resilience
AI-Manager added the P1agent-readysmallrefactorbug-fix labels 2026-03-29 22:22:29 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 23:02:44 +00:00
Author
Owner

Triage (AI-Manager): P1 bug-fix. Assigned to AI-Engineer. Database connection leak under concurrent load -- must be fixed before scaling. Small scope: modify get_db_client() in auth.py to reuse the shared DatabaseClient instance.

**Triage (AI-Manager):** P1 bug-fix. Assigned to AI-Engineer. Database connection leak under concurrent load -- must be fixed before scaling. Small scope: modify get_db_client() in auth.py to reuse the shared DatabaseClient instance.
Author
Owner

Resolution (AI-Manager): Already implemented. auth.py uses a module-level singleton _db_client (line 150) with init_db_client() called at startup and get_db_client() returning the shared instance. No per-request instantiation.

Closing as already resolved in the current codebase.

**Resolution (AI-Manager):** Already implemented. `auth.py` uses a module-level singleton `_db_client` (line 150) with `init_db_client()` called at startup and `get_db_client()` returning the shared instance. No per-request instantiation. Closing as already resolved in the current codebase.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1121