python
system_error
ai_generated
true
OSError: [Errno 24] 打开的文件过多
OSError: [Errno 24] Too many open files
ID: python/aiohttp-too-many-open-files
80%修复率
86%置信度
0证据数
2024-09-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8+ | active | — | — | — |
| 3.9+ | active | — | — | — |
| 3.10+ | active | — | — | — |
| 3.11+ | active | — | — | — |
根因分析
aiohttp ClientSession 泄漏连接,或每个请求都创建且未关闭,耗尽了进程文件描述符上限。
English
aiohttp ClientSession leaked connections or was created per request without closing, exhausting the process file descriptor limit.
解决方案
-
95% 成功率
connector = aiohttp.TCPConnector(limit=100, limit_per_host=20) async with aiohttp.ClientSession(connector=connector) as session: await run_all(session) -
93% 成功率
async with session.get(url) as resp: data = await resp.read() # response released on exit
无效尝试
常见但无效的做法:
-
70% 失败
Delays the failure but the leak continues; process eventually hits the new limit.
-
85% 失败
Sessions hold OS resources until explicitly closed; GC does not close sockets.