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

HttpClient does't respect DNS changes #28

Open
AdaskoTheBeAsT opened this issue Nov 19, 2020 · 6 comments
Open

HttpClient does't respect DNS changes #28

AdaskoTheBeAsT opened this issue Nov 19, 2020 · 6 comments
Labels

Comments

@AdaskoTheBeAsT
Copy link

hi
as described in article
https://josef.codes/you-are-probably-still-using-httpclient-wrong-and-it-is-destabilizing-your-software/

"
The original and well-known HttpClient class can be easily used, but in some cases, it isn't being properly used by many developers.
As a first issue, while this class is disposable, using it with the using statement is not the best choice because even when you dispose HttpClient object, the underlying socket is not immediately released and can cause a serious issue named ‘sockets exhaustion’.

Therefore, HttpClient is intended to be instantiated once and reused throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads. That issue will result in SocketException errors. Possible approaches to solve that problem are based on the creation of the HttpClient object as singleton or static.

But there’s a second issue with HttpClient that you can have when you use it as singleton or static object. In this case, a singleton or static HttpClient doesn't respect DNS changes.
To address those mentioned issues and make the management of HttpClient instances easier, .NET Core 2.1 introduced a new HttpClientFactory...
"

do you think that introducing HttpClientFactory will be valuable?
do you accept pull requests? ;)

@bertt
Copy link
Contributor

bertt commented Nov 19, 2020

Hi, what specific reproducible problem did you encounter (if any)?

@AdaskoTheBeAsT
Copy link
Author

I will need to think how to simulate DNS change... quite tricky

@DLade
Copy link
Contributor

DLade commented Nov 23, 2020

I will need to think how to simulate DNS change... quite tricky

I wonder why you wanna do such a complicated thing. Its no need in practice (on production system) by that.
If the DNS changes the services are usually just restarted.
(and alot of organizational stuff happens then ... thousands of people needs to be informed)

Maybe I don't see any usecase and you have one, but I'm although not sure where is the need for this client.

@DLade
Copy link
Contributor

DLade commented Nov 25, 2020

I had a deeper look and I guess we're using it a good way:
https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

Where is the value of using the Factory if we just need ONE client?

@AdaskoTheBeAsT
Copy link
Author

I am afraid that hosting app in cloud with high resilliency requirement can expose some troubles.
I am not an expert in that area anyway looking at thread
dotnet/runtime#18348
seems that such things are possible

@DLade
Copy link
Contributor

DLade commented Jan 8, 2021

Maybe this ist the problem with sockets when using the HttpClient parallel:

https://makolyte.com/csharp-how-to-make-concurrent-requests-with-httpclient/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants