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

Bad usage of HttpClient #32

Open
PhilWeisz opened this issue Aug 23, 2023 · 0 comments
Open

Bad usage of HttpClient #32

PhilWeisz opened this issue Aug 23, 2023 · 0 comments

Comments

@PhilWeisz
Copy link

PhilWeisz commented Aug 23, 2023

AsyncImage uses HttpClient in several bad ways:
Currently inside AsyncImage.cs:
using var client = new HttpClient(); Link

I think it's a bad practice create a new HttpClient per control and force the auto-disposal of the HttpClient.

Why:
When opening many AsyncImages we create many clients in parallel to load the images which in turn:

  1. provoke socket-exhaustion, leading to a System.Net.Sockets.Exception (after disposing the HttpClient that socket is not instantly cleared, so it remains unusable for quite some time, in the TIME_WAIT state)
  2. provoke hitting rate-limits of the server (in case the images are all loaded from the same server)

What AsyncImage should do:
AsyncImage should enable supplying a HttpClient by the consumer in order to allow shared use of HttpClient(s) which can handle multiple requests in parallel and this would address both these problems.
If the developer wants to use that auto-disposing feature he should set some boolean flag - however, auto-disposing should ultimately be disabled by default (in order to prevent the Socket-Exhaustion issue). And in the Control's Help-Text the Socket-Exhaustion-Problem should maybe get referenced in the infotext of that AutoDisposeHttpClient -Property
[Which would only be required if the Consumer did not supply his own HttpClient instance, which can have rate-limiting integrated etc. and which should be disposed by himself and not the control then]

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

1 participant