Geocoding.net
Geocoding.net copied to clipboard
Shouldn't dispose HttpClient
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.
Yes, I agree the class should dispose it in its dispose.
I'm more than happy to provide a PR for this change.
👍