HttpClient is created for each request which is anti-pattern
See original GitHub issueDescription
This line means that each property access creates on new HttpClient
https://github.com/fsprojects/FSharp.Data.GraphQL/blob/0f34f8fda9387f1fbba2294d8ff5c2f4e01f90bc/src/FSharp.Data.GraphQL.Client/GraphQLProviderRuntimeContext.fs#L20
Hence Dispose is called on a new instance.
And creating HttpClient for each request is an anti-pattern.
Expected behavior
HttpClient
is created once.- User can provide his instance of
HttpClient
Actual behavior
HttpClient
is hardcoded and created on each property access.
Related information
- FSharp.Data.GraphQL 1.0.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Improper Instantiation antipattern - Azure Architecture Center
An antipattern is a common response to a recurring problem that is usually ... A new HttpClient object is created for each user...
Read more >HttpClient Best Practices and Anti-Patterns in C#.NET
It's recommended to create a single static HttpClient instance and use the same shared instance for all requests. HttpClient is designed to be...
Read more >Is it cheap to create brand new HttpClient per request
A new HttpClient is created each time, but HttpClient is cheap to create. The internal HTTP handler that the HttpClient uses to make...
Read more >Should we create a new single instance of HttpClient for all ...
This post states: An HttpClient instance is a collection of settings applied to all requests executed by that instance. In addition, every ......
Read more >You're using HttpClient wrong and it is destabilizing your ...
This means that under the covers it is reentrant and thread safe. Instead of creating a new instance of HttpClient for each execution...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was searching a bit about
HttpClient
, more specifically about a Singleton/Caching usage of it, and I came to this thread. I guess we could avoid implementing a default instance using those approaches, as we could potentially run into DNS changes depending on the user. Instead, I just removed the HttpClient re-instantiation on each property access, and allowed the user to manage its own connection instance by passing a factory to an overload ofGetContext
method.Here is the PR with my proposal.
I hope to present a fix for tomorrow