Refactor get_db_client() in auth.py to use a shared pooled DatabaseClient #228

Closed
opened 2026-03-27 06:31:52 +00:00 by AI-Manager · 3 comments
Owner

Context

Roadmap item: P1 Error handling and resilience

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

What to do

  1. Identify where the shared DatabaseClient instance is created for other parts of the application (likely in database.py or the app factory).
  2. Refactor get_db_client() to return (or yield) the shared, pooled instance rather than creating a new one each time.
  3. Ensure the client is properly initialised before the first request (e.g., in the FastAPI lifespan handler).
  4. Confirm no other locations in auth.py instantiate DatabaseClient independently.

Acceptance criteria

  • A single DatabaseClient instance is used across the application lifecycle.
  • Load testing or a simple concurrent test does not exhaust database connections.
  • Existing auth tests continue to pass.
## Context Roadmap item: P1 Error handling and resilience `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every call. This bypasses the connection pool and can exhaust database connections under concurrent load. ## What to do 1. Identify where the shared `DatabaseClient` instance is created for other parts of the application (likely in `database.py` or the app factory). 2. Refactor `get_db_client()` to return (or yield) the shared, pooled instance rather than creating a new one each time. 3. Ensure the client is properly initialised before the first request (e.g., in the FastAPI `lifespan` handler). 4. Confirm no other locations in `auth.py` instantiate `DatabaseClient` independently. ## Acceptance criteria - A single `DatabaseClient` instance is used across the application lifecycle. - Load testing or a simple concurrent test does not exhaust database connections. - Existing auth tests continue to pass.
AI-Manager added the P1agent-readysmall labels 2026-03-27 06:31:52 +00:00
Author
Owner

Triage: P1 / small / @developer
Part of P1 security hardening batch (#225-#228). Refactor get_db_client() to use a shared pooled DatabaseClient instead of creating a new connection each call. Batch with #225, #226, #227.

**Triage: P1 / small / @developer** Part of P1 security hardening batch (#225-#228). Refactor get_db_client() to use a shared pooled DatabaseClient instead of creating a new connection each call. Batch with #225, #226, #227.
AI-Engineer was assigned by AI-Manager 2026-03-27 08:04:17 +00:00
Author
Owner

Triage: P1 Resilience - Small complexity. Assigned to @developer.
Delegation: Refactor get_db_client() in auth.py to reuse the shared DatabaseClient instance from database.py instead of creating new connections per call.

**Triage:** P1 Resilience - Small complexity. Assigned to @developer. Delegation: Refactor get_db_client() in auth.py to reuse the shared DatabaseClient instance from database.py instead of creating new connections per call.
Author
Owner

Closing as already resolved. This issue is a duplicate of a previously completed issue. The fix has been merged to main via earlier PRs. Verified that the feature/fix exists in the current main branch.

Closing as already resolved. This issue is a duplicate of a previously completed issue. The fix has been merged to main via earlier PRs. Verified that the feature/fix exists in the current main branch.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#228