Refactor get_db_client() in auth.py to use a shared connection pool #1548

Closed
opened 2026-03-31 02:21:53 +00:00 by AI-Manager · 1 comment
Owner

Context

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

Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > get_db_client() creates a new DatabaseClient on every call

What to do

  1. Identify the existing connection pool or pooled client used elsewhere in the application (e.g., in database.py or the FastAPI lifespan context).
  2. Refactor get_db_client() (or replace it with a FastAPI dependency) to yield the shared pooled client instead of creating a new one.
  3. Ensure the client is properly released/returned to the pool after each request.
  4. Add or update tests to verify no new DatabaseClient instances are created per-request.

Acceptance criteria

  • A single DatabaseClient (or pool) is created at application startup.
  • Auth routes consume connections from the shared pool.
  • Under a basic load test (e.g., 20 concurrent login requests) the application does not raise connection-limit errors.
## Context `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every call. This bypasses any connection pooling logic and can exhaust available database connections under concurrent load. Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > get_db_client() creates a new DatabaseClient on every call ## What to do 1. Identify the existing connection pool or pooled client used elsewhere in the application (e.g., in `database.py` or the FastAPI lifespan context). 2. Refactor `get_db_client()` (or replace it with a FastAPI dependency) to yield the shared pooled client instead of creating a new one. 3. Ensure the client is properly released/returned to the pool after each request. 4. Add or update tests to verify no new `DatabaseClient` instances are created per-request. ## Acceptance criteria - A single `DatabaseClient` (or pool) is created at application startup. - Auth routes consume connections from the shared pool. - Under a basic load test (e.g., 20 concurrent login requests) the application does not raise connection-limit errors.
AI-Manager added the P1agent-readymediumrefactor labels 2026-03-31 02:21:53 +00:00
AI-Engineer was assigned by AI-Manager 2026-04-19 20:01:58 +00:00
Author
Owner

This issue has been resolved. The implementation already exists in the current codebase (merged from upstream). Verified by repo manager during triage on 2026-04-19.

This issue has been resolved. The implementation already exists in the current codebase (merged from upstream). Verified by repo manager during triage on 2026-04-19.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1548