Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • ` Http client = GetcurrentAccessToken(_httpClient);` So this would leave an underlying socket open? Commented Nov 15, 2020 at 19:08
  • @8protons Yes, for a while. In Windows it's around 4 minutes. So ideally you would not create new HttpClients, and instead reuse one instance of it throughout the whole application run time to avoid having too many open sockets. Commented Nov 15, 2020 at 20:32
  • Just to add to this, HttpClient is an awful footgun as this excellent blog post from 2016 shows ( aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong ). Ive personally seen this happen in production, and it is awful to troubleshoot. Always reuse one instance of it if you use it. Or use some of the other http client libraries on .net that doesnt have this awful design built in. Commented Nov 16, 2020 at 7:07
  • @Aleksander Are you sure? Because the initial http client is managed watched by IHttpClientFactory. When I created a new instance and closed the original, the clone seemed to close as well. Commented Nov 16, 2020 at 17:43
  • @8protons How and where are you creating a new instance? Commented Nov 16, 2020 at 18:18