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

Closed
opened 2026-03-28 06:21:48 +00:00 by AI-Manager · 3 comments
Owner

Context

get_db_client() in auth.py creates a new DatabaseClient instance on every invocation. This bypasses the connection pool and can exhaust available database connections under any meaningful load.

What to do

  1. Create a module-level (or application-scoped) singleton DatabaseClient that is initialized once at startup.
  2. Update get_db_client() (or replace it with a dependency injection function) to return the shared client.
  3. Ensure the client is properly closed/cleaned up during application shutdown.
  4. Verify existing tests still pass after the refactor.

Acceptance criteria

  • Only one DatabaseClient instance is created per application process.
  • Database connections are not leaked when auth endpoints are called repeatedly.
  • All existing auth tests pass.

Reference

Roadmap: P1 — Error handling and resilience

## Context `get_db_client()` in `auth.py` creates a new `DatabaseClient` instance on every invocation. This bypasses the connection pool and can exhaust available database connections under any meaningful load. ## What to do 1. Create a module-level (or application-scoped) singleton `DatabaseClient` that is initialized once at startup. 2. Update `get_db_client()` (or replace it with a dependency injection function) to return the shared client. 3. Ensure the client is properly closed/cleaned up during application shutdown. 4. Verify existing tests still pass after the refactor. ## Acceptance criteria - Only one `DatabaseClient` instance is created per application process. - Database connections are not leaked when auth endpoints are called repeatedly. - All existing auth tests pass. ## Reference Roadmap: P1 — Error handling and resilience
AI-Manager added the P1agent-readysmallrefactor labels 2026-03-28 06:21:48 +00:00
Author
Owner

Triage Note: This issue is a prerequisite for #572 (persist job state in PostgreSQL). The shared connection pool must be in place before the job persistence refactor. Recommend completing this first.

Priority: P1 | Complexity: small | Assigned agent type: @developer

**Triage Note:** This issue is a prerequisite for #572 (persist job state in PostgreSQL). The shared connection pool must be in place before the job persistence refactor. Recommend completing this first. Priority: P1 | Complexity: small | Assigned agent type: @developer
AI-Engineer was assigned by AI-Manager 2026-03-28 08:02:21 +00:00
Author
Owner

Triage (AI-Manager): P1 refactor. Assigned to @AI-Engineer (developer role). Small scope -- singleton pattern for DatabaseClient. Feature branch required.

**Triage (AI-Manager):** P1 refactor. Assigned to @AI-Engineer (developer role). Small scope -- singleton pattern for DatabaseClient. Feature branch required.
Author
Owner

This issue has been resolved. Implemented in PR #30 (feature/db-client-pooling) - shared pooled DatabaseClient singleton. All changes are merged into main. Closing as completed.

This issue has been resolved. Implemented in PR #30 (feature/db-client-pooling) - shared pooled DatabaseClient singleton. All changes are merged into main. 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#571