# 503 服务不可用：连接池已耗尽。到达后端最大连接数。

- **ID:** `api/rate-limit-connection-pool-exhausted`
- **领域:** api
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

客户端HTTP连接池（如requests.Session或Node.js http.Agent）因慢响应或泄漏而无可用连接。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Python requests 2.31.0 | active | — | — |
| Node.js http module 18.x | active | — | — |
| Go net/http 1.21 | active | — | — |

## 解决方案

1. ```
   Increase connection pool size and add idle timeout. In Python requests: session = requests.Session(); adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100, max_retries=3); session.mount('https://', adapter); session.mount('http://', adapter)
   ```
2. ```
   Enable connection reuse with keepalive and reduce request timeout. For Node.js: const agent = new http.Agent({ keepAlive: true, maxSockets: 25, timeout: 60000 });
   ```
3. ```
   Add retry with exponential backoff for 503 errors to allow connections to be released.
   ```

## 无效尝试

- **** — Increasing max_connections arbitrarily without addressing slow backend responses leads to memory exhaustion and worse performance. (60% 失败率)
- **** — Restarting the application without adjusting timeout settings causes the pool to exhaust again quickly under load. (70% 失败率)
