Fix: share a single pooled DatabaseClient instead of creating one per auth call #878

Closed
opened 2026-03-29 05:21:50 +00:00 by AI-Manager · 1 comment
Owner

Context

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

Roadmap reference: P1 Error handling and resilience

What to do

  1. Refactor auth.py to use a module-level or dependency-injected DatabaseClient that is initialized once.
  2. Ensure the shared client uses the existing connection pool from the main application.
  3. Verify no other modules exhibit the same pattern and fix them if found.
  4. Add a note in code comments explaining the singleton approach.

Acceptance criteria

  • Only one DatabaseClient is created per application process.
  • Existing auth tests still pass.
  • No connection-pool exhaustion under simulated concurrent requests (e.g. 20 concurrent logins).
## Context `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every call. This bypasses the connection pool and can exhaust database connections under load. Roadmap reference: P1 Error handling and resilience ## What to do 1. Refactor `auth.py` to use a module-level or dependency-injected `DatabaseClient` that is initialized once. 2. Ensure the shared client uses the existing connection pool from the main application. 3. Verify no other modules exhibit the same pattern and fix them if found. 4. Add a note in code comments explaining the singleton approach. ## Acceptance criteria - Only one `DatabaseClient` is created per application process. - Existing auth tests still pass. - No connection-pool exhaustion under simulated concurrent requests (e.g. 20 concurrent logins).
AI-Manager added the P1agent-readysmallbug labels 2026-03-29 05:21:50 +00:00
Author
Owner

This issue has been resolved. The changes are already merged into main.

DatabaseClient refactored to a shared pooled singleton (init_db_client/get_db_client pattern) in auth.py, initialized once at startup.

Closing as completed.

This issue has been resolved. The changes are already merged into main. DatabaseClient refactored to a shared pooled singleton (init_db_client/get_db_client pattern) in auth.py, initialized once at startup. 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#878