Disable autoconnect and set pool timeout on PooledPostgresqlDatabase #80

Open
opened 2026-03-27 04:07:00 +00:00 by cal · 1 comment
Owner

Problem

Two connection pool configuration concerns in app/db_engine.py:

  1. autoconnect=True (line 27) — Every attribute access on a model can implicitly acquire a connection from the pool, making lifecycle hard to reason about.
  2. timeout=0 (line 26) — Means "wait forever" for a pool connection. If the pool (max_connections=20) is exhausted, FastAPI workers hang indefinitely instead of returning a 503.

Fix

  • Set timeout=5 (or similar) to surface pool exhaustion as visible errors
  • Consider setting autoconnect=False and managing connections explicitly via middleware (related to the db.close() refactor issue)

Severity

Low — latent reliability risk under load.

## Problem Two connection pool configuration concerns in `app/db_engine.py`: 1. **`autoconnect=True`** (line 27) — Every attribute access on a model can implicitly acquire a connection from the pool, making lifecycle hard to reason about. 2. **`timeout=0`** (line 26) — Means "wait forever" for a pool connection. If the pool (max_connections=20) is exhausted, FastAPI workers hang indefinitely instead of returning a 503. ## Fix - Set `timeout=5` (or similar) to surface pool exhaustion as visible errors - Consider setting `autoconnect=False` and managing connections explicitly via middleware (related to the db.close() refactor issue) ## Severity Low — latent reliability risk under load.
Claude added the
ai-working
label 2026-03-27 05:31:20 +00:00
Claude removed the
ai-working
label 2026-03-27 05:37:01 +00:00
Collaborator

PR #87 opened: #87

Changes:

  • app/db_engine.py: timeout=0timeout=5 (pool exhaustion now errors after 5s instead of hanging), autoconnect=Trueautoconnect=False
  • app/main.py: Added db_connection_middleware that opens a connection at request start and closes it in a finally block — the explicit connection management companion to autoconnect=False. Existing per-handler db.close() calls still work correctly; the middleware's close is a no-op if the handler already returned the connection to the pool.
PR #87 opened: https://git.manticorum.com/cal/major-domo-database/pulls/87 **Changes:** - `app/db_engine.py`: `timeout=0` → `timeout=5` (pool exhaustion now errors after 5s instead of hanging), `autoconnect=True` → `autoconnect=False` - `app/main.py`: Added `db_connection_middleware` that opens a connection at request start and closes it in a `finally` block — the explicit connection management companion to `autoconnect=False`. Existing per-handler `db.close()` calls still work correctly; the middleware's close is a no-op if the handler already returned the connection to the pool.
Claude added the
ai-pr-opened
label 2026-03-27 05:37:07 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-database#80
No description provided.