Extremely Slow Preflight Requests

Tobias Haimerl 0 Reputation points
2024-07-12T16:51:21.1066667+00:00

We use an App Service hosting a WebApi (C# .NET 8). CORS is setup directly in Azure. This and one client application (Angular) are the only Apps inside the App Service Plan (P2v2).

Today we have massive slow downs in Preflight Requests from the Client to the API, which means around 5-30 seconds (!) And what is worse, that not all of those requests are slow, but only around 20%.

While trying to contact the support some problem solving tools show up and tell us that there is a problem with SNAT Port exhaustion. But we do not see any increase in requests in comparisson to other days.

We already did the following:

  • Redeploy Application
  • Restart App Service
  • Scale out to much more Instances as we actually need
  • App Service runs as Always On

All instances are healthy by the Health Check results. And there is nothing to see in the Health Center of our App Service.

What can we do about those issues?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,403 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,408 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 24,971 Reputation points Microsoft Employee
    2024-07-18T06:44:59.79+00:00

    Tobias Haimerl, Apologies for the delayed response here.

    I see that you have tried multiple steps to isolate the issue.
    Just to highlight, SNAT port exhaustion can occur when there are too many outbound connections from your App Service, which can cause delays in establishing new connections. This can result in slow preflight requests.

    Each instance on Azure App service is initially given a preallocated number of 128 SNAT ports. The SNAT port limit affects opening connections to the same address and port combination

    If you haven't done this already, to further isolate the issue:

    1. You may leverage Azure Monitor to monitor the number of outbound connections and identify any spikes or unusual patterns. If you see a high number of outbound connections, you may need to optimize your application to reduce the number of connections.
    2. By default, each instance of an App Service has 128 SNAT ports. I understand you have scale-out/you may consider to test by scaling up your App Service plan (ASP).
    3. Depending on your setup/requirement, you may consider to use Azure CDN which can help reduce the number of outbound connections from your App Service by caching static content and serving it from a nearby edge location.

    Further, refer the doc steps outlined to avoid the SNAT port exhaustion problem.

    To fetch more details about the logs : Enable and review logs to fetch more details about the error

    Kindly let us know, I'll follow-up with you further.


    If the answer helped (pointed, you in the right direction) > please click Accept Answer to benefit the community find answers quickly to similar question.

    0 comments No comments