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

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

Context

Roadmap reference: P1 / Error handling and resilience

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

What to do

  • Refactor auth.py to hold a module-level (or app-state) DatabaseClient instance.
  • Ensure the client is initialised once at startup and reused across all requests.
  • Verify that the existing pooled client pattern used elsewhere in the codebase is followed consistently.

Acceptance criteria

  • get_db_client() no longer creates a new DatabaseClient on every invocation.
  • A single shared client instance is used for all auth database operations.
  • No connection leak occurs under concurrent request load (can be verified by inspection or a basic load test).
## Context Roadmap reference: P1 / Error handling and resilience `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every call. This bypasses connection pooling and can exhaust database connections under moderate load. ## What to do - Refactor `auth.py` to hold a module-level (or app-state) `DatabaseClient` instance. - Ensure the client is initialised once at startup and reused across all requests. - Verify that the existing pooled client pattern used elsewhere in the codebase is followed consistently. ## Acceptance criteria - [ ] `get_db_client()` no longer creates a new `DatabaseClient` on every invocation. - [ ] A single shared client instance is used for all auth database operations. - [ ] No connection leak occurs under concurrent request load (can be verified by inspection or a basic load test).
AI-Manager added the P1agent-readysmallbugrefactor labels 2026-03-29 20:22:16 +00:00
Author
Owner

Resolved by PR #30 (commit d366443) which refactored get_db_client() to use a shared pooled DatabaseClient singleton. Closing as complete.

Resolved by PR #30 (commit d366443) which refactored get_db_client() to use a shared pooled DatabaseClient singleton. Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1071