Deivydas Voroneckis
Deivydas Voroneckis

Reputation: 2483

Azure App service returns 502 bad gateway from HttpClient

I have an app service (plan B2) running on Azure.

My integration tests running from docker container are calling some app service endpoints one by one and sometimes receive 500 or 502 error.

When I debug tests I make some pauses between calls and all requests work successfully. Also, when I scale up my app service, everything works properly.(I don't want to scale up because cpu and other params are low.)

In my tests I have only one HttpClient and I dispose it at the end so I don't think there should be any connections leaks.

Also, in TCP Connections I have around 60 total connections while in Azure docs the limit is 1,920. enter image description here

enter image description here

This app is not accessed by any users but here it says that I had the maximum connections. Is there any way how can I track these connections? Why when I receive these 5xx errors I don't see anything in app insights? Also how 15 connections can exceed the limit when the limit is 1920? Are these connections related to my errors and how they can be fixed?

Upvotes: 1

Views: 3012

Answers (1)

Thiago Custodio
Thiago Custodio

Reputation: 18387

You don't see them in Application Insights because they're happening at IIS level which is breaking the request, and because of that, data is not being sent to Application Insights.

The place to look for information is "Diagnose and solve problems", then "Availability and Performance". More info in here:

https://learn.microsoft.com/en-us/azure/app-service/overview-diagnostics

PS: I do think the problem is related to the Dispose of your HTTPClient. It's a well known issue and the reason why they've introduced HttpClientFactory. More info in here:

https://www.stevejgordon.co.uk/httpclient-creation-and-disposal-internals-should-i-dispose-of-httpclient

https://stackoverflow.com/a/15708633/1384539

Upvotes: 1

Related Questions