Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClient not Threadsafe #322

Open
rvdzwet opened this issue Jan 2, 2025 · 1 comment
Open

HttpClient not Threadsafe #322

rvdzwet opened this issue Jan 2, 2025 · 1 comment

Comments

@rvdzwet
Copy link

rvdzwet commented Jan 2, 2025

The HttpClient should be created with the IHttpClientFactory on every request, as the HttpClient is not thread safe. It disposes itself and therefor the BaseApi class cannot be longlived

@michielpost
Copy link
Owner

Hi @rvdzwet ,

Thanks for creating a GitHub issue.

The HueApi is only creating 1 HttpClient, that gets reused for every request. It's not making a new HttpClient for every request, so there shouldn't be any issue.
HttpClient does not dispose of itself, as long as you keep the LocalHueApi alive, you keep reusing the same HttpClient. It's not recommended to create new LocalHueApi instances every time. Please reuse a single instance.

If you want more control, it's also possible to provide your own HttpClient to the LocalHueApi constructor, in that case you are responsible for providing a HttpClient, and you can get that HttpClient from a IHttpClientFactory in your own code.

Let me know if you have a specific usecase where the current setup causes an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants