HTTP 503 cloud resource_error ai_generated true

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

ID: cloud/azure-app-service-connection-limit-exceeded

Also available as: JSON · Markdown · 中文
82%Fix Rate
82%Confidence
1Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Azure App Service Windows 2022 active
.NET 8.0 active

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.

generic

中文

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

Official Documentation

https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#connection-limits

Workarounds

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

中文步骤

  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)

Dead Ends

Common approaches that don't work:

  1. 80% fail

    This only affects outgoing HTTP connections; the error is about incoming connections to the App Service, not outbound.

  2. 90% fail

    Restart resets connections temporarily but does not address the root cause; connections quickly rebuild and exceed the limit again.

  3. 70% fail

    Disabling keep-alive may increase connection churn and worsen the issue, as each request opens a new connection.