0

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?
Saravanan
  • 604
  • 1
  • 8
  • 20
  • 443 is the default HTTPS port, as you probably know, but that's on the listener side - clients get a random one assigned to their connection, so do you get this error on the server or the client? - FWIW, it really sounds like the server is trying to open a new listener while the old one is still active. – 500 - Internal Server Error Jan 20 '21 at 15:54
  • ServiceA is calling ServiceB and this error is thrown during the call on the client (ServiceA). Are you saying that the ServiceB is throwing this exception? – Saravanan Jan 20 '21 at 16:00
  • That's what it sounds like. – 500 - Internal Server Error Jan 20 '21 at 16:39

0 Answers0