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

Shouldn't dispose HttpClient #99

Open
dcomartin opened this issue May 9, 2018 · 1 comment
Open

Shouldn't dispose HttpClient #99

dcomartin opened this issue May 9, 2018 · 1 comment

Comments

@dcomartin
Copy link

It appears the httpClient is disposed via using statement each time a request is processed.

https://github.com/chadly/Geocoding.net/blob/master/src/Geocoding.Google/GoogleGeocoder.cs#L164

This should not be happening and the httpClient should be reused.

https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

HttpClient is intended to be instantiated once and reused throughout the life of an application. The following conditions can result in SocketException errors:

Creating a new HttpClient instance per request.
Server under heavy load.
Creating a new HttpClient instance per request can exhaust the available sockets.

I'd recommend that the class itself is disposable and cleans itself up, as well as a second option which is having the ctor take an HttpClient as a dependency.

I'm more than happy to provide a PR for this change.

@chadly
Copy link
Owner

chadly commented May 9, 2018

Yes, I agree the class should dispose it in its dispose.

I'm more than happy to provide a PR for this change.

👍

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