Skip to content

feat(db): configurable connection pool tuning for MySQL / PostgreSQL#72

Open
pushiwuhua7 wants to merge 1 commit into
datahub-project:mainfrom
pushiwuhua7:feat/db-pool-config
Open

feat(db): configurable connection pool tuning for MySQL / PostgreSQL#72
pushiwuhua7 wants to merge 1 commit into
datahub-project:mainfrom
pushiwuhua7:feat/db-pool-config

Conversation

@pushiwuhua7
Copy link
Copy Markdown

Why

Without pool_pre_ping=True, asyncpg leaves connections that were
interrupted by task cancellation (CancelledError) in a half-broken
state inside the SQLAlchemy pool. The next checkout of such a
connection hangs indefinitely, which under concurrent load presents
as the whole app stalling — even though no obvious error surfaces.

The default AsyncAdaptedQueuePool (pool_size=5, max_overflow=10,
pool_timeout=30s) is also too small for production deployments and
provides no recycle behavior to survive managed-PG idle timeouts.

What

Expose the standard SQLAlchemy pool knobs via env vars, applied to
non-SQLite engines only:

Env var Default Purpose
DB_POOL_SIZE 10 Persistent pool size
DB_MAX_OVERFLOW 20 Burst capacity
DB_POOL_PRE_PING true Detect broken connections on checkout (asyncpg critical)
DB_POOL_TIMEOUT 10 Fail-fast under load (SQLA default 30s "hangs")

SQLite path is unchanged.

Test

  • Unit: settings load with defaults, env-var override verified
  • Manual: previously-reproducible asyncpg hang under concurrent SSE
    agent execution no longer occurs after enabling pool_pre_ping

Without pool_pre_ping=True, asyncpg leaves cancelled-task connections
in a broken state inside the pool, causing the next checkout to hang
indefinitely under concurrent load. Expose the standard SQLAlchemy
pool knobs (size / max_overflow / recycle / pre_ping / timeout) via
env vars with sensible defaults, applied to non-SQLite engines only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant