# System.Net.Http.HttpRequestException：主机的连接数限制已超出

- **ID:** `cloud/azure-app-service-connection-limit-exceeded`
- **领域:** cloud
- **类别:** resource_error
- **错误码:** `HTTP 503`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Azure应用服务计划有默认连接限制（如每个实例300个），因扩展不足或长连接耗尽。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Azure App Service Windows 2022 | active | — | — |
| .NET 8.0 | active | — | — |

## 解决方案

1. ```
   Scale out the App Service plan to more instances (e.g., increase instance count from 1 to 3) to distribute connections
   ```
2. ```
   Enable Always On in App Service settings to prevent idle connection drops and reduce churn
   ```
3. ```
   Set `ServicePointManager.DefaultConnectionLimit = int.MaxValue` in Global.asax.cs to increase outbound connection limit (if error is outbound)
   ```

## 无效尝试

- **** — This only affects outgoing HTTP connections; the error is about incoming connections to the App Service, not outbound. (80% 失败率)
- **** — Restart resets connections temporarily but does not address the root cause; connections quickly rebuild and exceed the limit again. (90% 失败率)
- **** — Disabling keep-alive may increase connection churn and worsen the issue, as each request opens a new connection. (70% 失败率)
