Flagsmith / Flagsmith/flagsmith-dotnet-client

HttpClient is not created and managed with IHttpClientFactory

Open
#190 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
20
Forks
15
PR merge metrics
No merged PRs in 30d

Description

[MS article](https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests) on why you should not be managing your `HttpClient` manually and instead use `IHttpClientFactory`. See [here](https://github.com/Flagsmith/flagsmith-dotnet-client/blob/main/Flagsmith.FlagsmithClient/FlagsmithConfiguration.cs#L89) for line that should be updated.

Important tidbits here:
"_Another issue that developers run into is when using a shared instance of `HttpClient` in long-running processes. In a situation where the `HttpClient` is instantiated as a singleton or a static object, it fails to handle the DNS changes as described in this [issue](https://github.com/dotnet/runtime/issues/18348) of the dotnet/runtime GitHub repository._"

_"Though this class implements `IDisposable`, declaring and instantiating it within a using statement is not preferred because when the `HttpClient` object gets disposed of, the underlying socket is not immediately released, which can lead to a socket exhaustion problem. For more information about this issue, see the blog post [You're using `HttpClient` wrong and it's destabilizing your software](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/)."_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with Flagsmith.FlagsmithClient/FlagsmithConfiguration.cs at line 89 and read the surrounding client construction and its callers. Compare that setup with the linked Microsoft IHttpClientFactory guidance; done means the client is created and managed through the factory rather than manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.