python
runtime_error
ai_generated
true
sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30.00
ID: python/fastapi-db-session-not-closed
80%Fix Rate
88%Confidence
0Evidence
2024-09-17First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
Root Cause
Dependency yields a DB session but never closes it on exceptions, leaking connections until the pool is exhausted.
generic中文
依赖项 yield 了数据库会话但异常时未关闭,连接泄漏直至连接池耗尽。
Workarounds
-
97% success
def get_db(): db = SessionLocal() try: yield db finally: db.close() -
96% success
def get_db(): with SessionLocal() as db: yield db
Dead Ends
Common approaches that don't work:
-
80% fail
Delays exhaustion; underlying leak persists.
-
85% fail
Detects dead connections, does not free leaked ones.