Port Exhaustion on Azure Web App

We have recently converted many of our “batch” type services to using MQ, (which is awesome by the way), and performance has gone way way up which is fantastic, plus free retry is huge.

We are however now running into what I believe is port exhaustion, running on a decent sized WebApp instance using thread counts of between 2 to 5 on 8 different services methods. Are there any tricks to reducing the internal consumption of the tcp/ip stack between services? We are using a combination of Gateway and HostContext.Resolve() depending on the context of the method.

2018-11-20 22:09:26.429 []:ERROR:Service Ex System.AggregateException: One or more errors occurred. (Only one usage of each socket address (protocol/network address/port) is normally permitted) —> System.Net.Http.HttpRequestException: Only one usage of each socket address (protocol/network address/port) is normally permitted —> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted

Can’t really give any recommendations without being able to see the code in question but an overall recommendation to reduce connections is to use async.

Note MSDN has some solutions for this particular exception:

I think perhaps service stack messaging here is the victim of another API that is being called with an HTTP client at a high amount of parallelism. I’ve made some adjustments , stopped new’ing it so much and its gotten a lot better (still more to do… )

Note ServiceStack Messaging doesn’t typically use any HTTP unless you’re using a HTTP ReplyTo address.