HttpWebRequest Port Exhaustion

前端 未结 3 873
梦毁少年i
梦毁少年i 2021-02-09 22:39

We are using a Windows Service to make very frequent HTTP calls to an internal REST service (20-40 calls per second), but notice a long delay in getting responses after the serv

3条回答
  •  北海茫月
    2021-02-09 23:16

    It's probably related to the same issue that many users run into when using the HttpClient class and classes that use the HttpClient internally. As a result of the HttpClient implementing the IDisposable interface, you'll find many developers having the urge to wrap any new instances of the class in a using statement. There is just one problem with that; When the HttpClient object gets disposed of the attached ports remain blocked for 5 minutes 'TIME_WAIT' until they get released by the OS.

    I usually use a single HttpClient instance (singleton) and use fully qualified URLs in combination with asynchronous calls.

提交回复
热议问题