1

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?

Deivydas Voroneckis
  • 1,973
  • 3
  • 19
  • 40

1 Answers1

1

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

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • It seems relevant but still I have only one `HttpClient` intance which is used for all requests, how can it exceed connections? – Deivydas Voroneckis Nov 17 '20 at 15:17
  • do one test and use HTTPClientFactory. If the problem remains, try to scale up your App Service Plan. There's nothing I can add besides what it's already in my answer. – Thiago Custodio Nov 17 '20 at 15:20
  • Thank you, it works now! The problem probably was that my `HttpClient` instance worked when I ran tests for the first time but failed on the second run because the previous connections were still open. Is `IHttpClientFactory` can reuse connections from previous tests run or it still creates completely new connection? Because it is hard to understand why suddenly it started working. – Deivydas Voroneckis Nov 18 '20 at 08:42