How do I fix SNAT Exhaustion in App Service

Viewed 800

I'm having a problem with SNAT exhaustion in one of our Azure App Service based APIs:

SNAT

Our HTTPClient is written into a singleton that should instance only once (C#/.net 4.72)...

    public class CSClient : HttpClient
    {
        private static readonly CSClient Inst = new CSClient();

        static CSClient()
        {
        }

        private CSClient() : base()
        {
            Timeout = TimeSpan.FromSeconds(60);
            BaseAddress = new Uri(ConfigurationManager.AppSettings["***.BaseURL"]);
        }

        public static HttpClient Instance
        {
            get
            {
                return Inst;
            }
        }
    }

Then called

public class ContentRepository : IContentRepository
    {
        protected HttpClient htc = CSClient.Instance;

        public async Task<Content> GetContentAsync(Content ct)
        {
            using (var req = new HttpRequestMessage(HttpMethod.Get, ConfigurationManager.AppSettings["***.BaseUrl"] + "/api/v2/nodes/" + ct.Id))
            {
                var response = await htc.SendAsync(req);

                if (response.IsSuccessStatusCode)
                {
                    var job = JObject.Parse(await response.Content.ReadAsStringAsync());
                    var respct = OTtoContent(job["results"]);
                    return respct;
                }
                else
                {
                    return null;
                }
            }
        }
    }

I'm not sure why the extra connections are being made. Is my singleton correct? Anything else I can do with the httpclient? Anything to do with the app service, short of adding resources? Thanks for any help in advance.

2 Answers
Related