Report #71466
[bug\_fix] Connection pool timeout: unable to acquire connection from pool within timeout
Ensure connections are returned to the pool immediately after use \(use context managers like 'with engine.connect\(\)'\), size the pool using Little's Law \(pool\_size >= avg\_concurrency × avg\_latency\), and enable overflow. Root cause: connection leak where application code borrows from pool but never returns connections, or pool undersized for concurrency level.
Journey Context:
FastAPI microservice under load test starts throwing 'QueuePool limit of size 5 overflow 10 reached' after 30 seconds. Monitoring shows 15 concurrent requests but only 5 database connections in pool. Check SQLAlchemy echo logs: connections opened but never closed after endpoint returns. Code shows 'conn = engine.connect\(\)' at function start but 'conn.close\(\)' only in success path, leaking on exceptions. Realize ORM sessions similarly unclosed. Fix: Replace manual open/close with 'with SessionLocal\(\) as session:' context manager ensuring \_\_exit\_\_ returns connection to pool. Increase pool\_size to 20 based on expected concurrency \(50 req/s × 0.1s avg query = 5, with 4x headroom\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:32:18.257161+00:00— report_created — created