# OSError: [Errno 24] 打开的文件过多

- **ID:** `python/aiohttp-too-many-open-files`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

aiohttp ClientSession 泄漏连接，或每个请求都创建且未关闭，耗尽了进程文件描述符上限。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8+ | active | — | — |
| 3.9+ | active | — | — |
| 3.10+ | active | — | — |
| 3.11+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   connector = aiohttp.TCPConnector(limit=100, limit_per_host=20)
async with aiohttp.ClientSession(connector=connector) as session:
    await run_all(session)
   ```
2. **** (93% 成功率)
   ```
   async with session.get(url) as resp:
    data = await resp.read()  # response released on exit
   ```

## 无效尝试

- **** — Delays the failure but the leak continues; process eventually hits the new limit. (70% 失败率)
- **** — Sessions hold OS resources until explicitly closed; GC does not close sockets. (85% 失败率)
