Unable to resolve (502) Bad Gateway error in Azure App Service

Viewed 9036

We have an App Service Plan (P2v2: 1) that has 6 .Net Core Web API's & 2 Web Jobs deployed.

Of late, 1 of the Web API periodically starts emitting (502) Bad Gateway error. The error seems to resolve on it's own or we need to restart the App Service.

The Avg CPU % we saw was 42.x % and Avg Memory % was around 32.x %

This is really driving us nuts because we don't see any Application errors.

We are badly in need of hints to resolve this issue because this is running in Production.

1 Answers

502 errors can be multiple things.

  • there's a chance you're exceeding the maximum tcp connections for the plan (standard s3 while has an older hardware it contains the double of p2v2)

  • it can be timeout in your app too.

  • also check if you're using HttpClientFactory rather than HttpClient as it will reuse connections from the pool

The maximum IP connections are per instance and depend on the instance size: 1,920 per B1/S1/P1V2 instance, 3,968 per B2/S2/P2V2 instance, 8,064 per B3/S3/P3V2 instance.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/azure-subscription-service-limits#app-service-limits

The best thing you can do is inspect the diagnose and solve issue and select 500x error and analyze the report.

Related