# System.Net.Http.HttpRequestException: The connection limit for the host was exceeded

- **ID:** `cloud/azure-app-service-connection-limit-exceeded`
- **Domain:** cloud
- **Category:** resource_error
- **Error Code:** `HTTP 503`
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

Azure App Service plan has a default connection limit (e.g., 300 per instance) that is exhausted due to insufficient scaling or long-lived connections.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Azure App Service Windows 2022 | active | — | — |
| .NET 8.0 | active | — | — |

## Workarounds

1. **Scale out the App Service plan to more instances (e.g., increase instance count from 1 to 3) to distribute connections** (85% success)
   ```
   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** (80% success)
   ```
   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)** (75% success)
   ```
   Set `ServicePointManager.DefaultConnectionLimit = int.MaxValue` in Global.asax.cs to increase outbound connection limit (if error is outbound)
   ```

## Dead Ends

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