python
runtime_error
ai_generated
true
sqlalchemy.exc.TimeoutError: QueuePool 大小 5、溢出 10 已达上限,连接超时 30.00 秒。
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%修复率
88%置信度
0证据数
2024-09-17首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
根因分析
依赖项 yield 了数据库会话但异常时未关闭,连接泄漏直至连接池耗尽。
English
Dependency yields a DB session but never closes it on exceptions, leaking connections until the pool is exhausted.
解决方案
-
97% 成功率
def get_db(): db = SessionLocal() try: yield db finally: db.close() -
96% 成功率
def get_db(): with SessionLocal() as db: yield db
无效尝试
常见但无效的做法:
-
80% 失败
Delays exhaustion; underlying leak persists.
-
85% 失败
Detects dead connections, does not free leaked ones.