Geocoding.net icon indicating copy to clipboard operation
Geocoding.net copied to clipboard

Shouldn't dispose HttpClient

Open dcomartin opened this issue 7 years ago • 1 comments

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.

dcomartin avatar May 09 '18 15:05 dcomartin

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

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

👍

chadly avatar May 09 '18 15:05 chadly