I am hosting an asp.net web api on an azure web app. The app is hosted on 2 side by side instances of azure web apps.
However recently our peak requests have increased, and we have started seeing the following error in our logs:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
In our web server we make many short lived http post requests to additional servers using HttpClinet. From my research of the above error code, it seems that the underlying OS is running out of 'user' TCP ports. I first thought this was some bug with the HttpClient .net library. However we have tried a static instance of HttpClient as well as a using dispose method. Neither resolve our issue. The only thing that helps is us manually restarting the web app every hour, which is definitely not a long term solution.
I am unable to run 'netstat' on the azure web app to see what is happening with the sockets.
The number requests we are doing is roughly 100 000 a day. This should not be overloading one machine, never mind two. So something must be very wrong.
How can we resolve this issue?
I have some questions:
- Is httpclient up for the job, the job being thousands of http post requests?
- Is there anyway to force
HttpClientto usehttp2where it will do multiple requests on a single tcp socket. - What other technology options do have? Essentially we want to send a json object from one server to another and get a json object back as a response. Would something like
azure servicebus work where it would have several sockets and push many requests over those sockets?