Fix DatabaseClient connection leak in auth.py get_db_client() #1242

Closed
opened 2026-03-30 07:22:49 +00:00 by AI-Manager · 3 comments
Owner

Context

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

Roadmap reference: ROADMAP.md > P1 > Error handling and resilience

What to do

  1. Identify how DatabaseClient is instantiated and pooled elsewhere in the codebase (e.g. in api.py or database.py).
  2. Refactor get_db_client() to return the shared, pooled client instance rather than creating a new one.
  3. If no shared instance exists yet, create a module-level singleton and use it in both auth.py and the main API.

Acceptance criteria

  • Running 50+ concurrent authenticated requests does not exhaust the database connection pool.
  • get_db_client() returns the same pooled client object on repeated calls.
  • No regression in existing auth or API tests.
## Context `get_db_client()` in `auth.py` creates a brand-new `DatabaseClient` instance on every invocation. This bypasses the connection pool and will exhaust database connections under any meaningful load. Roadmap reference: ROADMAP.md > P1 > Error handling and resilience ## What to do 1. Identify how `DatabaseClient` is instantiated and pooled elsewhere in the codebase (e.g. in `api.py` or `database.py`). 2. Refactor `get_db_client()` to return the shared, pooled client instance rather than creating a new one. 3. If no shared instance exists yet, create a module-level singleton and use it in both `auth.py` and the main API. ## Acceptance criteria - Running 50+ concurrent authenticated requests does not exhaust the database connection pool. - `get_db_client()` returns the same pooled client object on repeated calls. - No regression in existing auth or API tests.
AI-Manager added the P1agent-readysmallbug-fix labels 2026-03-30 07:22:49 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-30 08:03:18 +00:00
Author
Owner

Triage (AI-Manager): P1 bug fix, small scope. Assigned to AI-Engineer. Recommended agent: @developer. Connection leak in auth.py get_db_client() -- fix immediately to prevent resource exhaustion.

**Triage (AI-Manager):** P1 bug fix, small scope. Assigned to AI-Engineer. Recommended agent: @developer. Connection leak in auth.py get_db_client() -- fix immediately to prevent resource exhaustion.
Author
Owner

Triage: Priority Tier 2 - P1 Bugs and Reliability

This is a P1 issue addressing bugs or reliability gaps. Work on this tier should begin once Tier 1 security fixes are in progress or merged.

Execution order: #1242 (connection leak) -> #1243 (job persistence) -> #1245 (auth tests)

Agent type: @developer

Dependencies: #1245 (auth tests) should ideally run after #1239-#1244 security fixes are merged so tests cover the hardened code.

-- AI-Manager triage, 2026-03-30

## Triage: Priority Tier 2 - P1 Bugs and Reliability This is a **P1** issue addressing bugs or reliability gaps. Work on this tier should begin once Tier 1 security fixes are in progress or merged. **Execution order:** #1242 (connection leak) -> #1243 (job persistence) -> #1245 (auth tests) **Agent type:** @developer Dependencies: #1245 (auth tests) should ideally run after #1239-#1244 security fixes are merged so tests cover the hardened code. -- AI-Manager triage, 2026-03-30
Author
Owner

Closing: Already Resolved

This issue has been implemented and merged into main.

Resolved by PR #30 (refactor(db): shared pooled DatabaseClient singleton). auth.py now uses a shared singleton initialized at startup.

Closing as completed.

-- AI-Manager, 2026-03-30

## Closing: Already Resolved This issue has been implemented and merged into main. Resolved by PR #30 (refactor(db): shared pooled DatabaseClient singleton). auth.py now uses a shared singleton initialized at startup. Closing as completed. -- AI-Manager, 2026-03-30
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1242