feat(db): configurable connection pool tuning for MySQL / PostgreSQL#72
Open
pushiwuhua7 wants to merge 1 commit into
Open
feat(db): configurable connection pool tuning for MySQL / PostgreSQL#72pushiwuhua7 wants to merge 1 commit into
pushiwuhua7 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Without
pool_pre_ping=True,asyncpgleaves connections that wereinterrupted 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:
DB_POOL_SIZEDB_MAX_OVERFLOWDB_POOL_PRE_PINGDB_POOL_TIMEOUTSQLite path is unchanged.
Test
agent execution no longer occurs after enabling
pool_pre_ping