Port exhaustion - ServicePointManager.ReusePort and IHttpClientFactory

287 views Asked by At

In our service, we are getting System.Net.Sockets.SocketException with the message Only one usage of each socket address (protocol/network address/port) is normally permitted xx.xxx.xx.xxx:443. This indicates that all the available network ports on the machine are exhausted.

The use case is that a lot of HTTP calls are made to the same endpoint with different inputs and the HttpClient is created every time using IHttpClientFactory (DefaultHttpClientFactory). Both the HttpClient and HttpResponseMessage are wrapped inside 'using' statement for proper disposal.

Questions:

  1. Is it okay to create too many HttpClient objects using IHttpClientFactory and dispose?
  2. Given that we are using IHttpClientFactory which avoids resource exhaustion problems, will it help in setting ServicePointManager.ReusePort to true to reduce this SocketException?
0

There are 0 answers