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 connections throwing System.Net.Sockets.SocketException after 21 seconds #27232

Closed
Tadimsky opened this issue Aug 25, 2018 · 6 comments
Labels
area-System.Net.Http question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@Tadimsky
Copy link

We have an issue in our services (running ASP.Net Core 2.1) where it takes about 21 seconds for HttpClient to "realize" that the service it is trying to connect to is down.

The message we finally get is:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
We then retry on a different service and that works, but it means our requests take 21+ seconds longer (and clients sometimes timeout because of it):

image

Is there a way to modify this timeout? Ideally we'd want it set to something more like 5 seconds.
It seems like it's a generic TCP timeout.

@davidsh
Copy link
Contributor

davidsh commented Aug 25, 2018

TCP timeouts are generally on the order of 21 seconds which is 7 seconds per each of the 3-legged SYNC, SYNC-ACK, ACK handshake. This is not currently configurable via HttpClient API since it is a low-level TCP timeout.

@karelz
Copy link
Member

karelz commented Aug 26, 2018

I don't think that Windows supports changes to these timeouts - only via reg keys.
If that's true, then this seems to be by design and we should close the question as answered.

@davidsh
Copy link
Contributor

davidsh commented Aug 26, 2018

@Tadimsky
Copy link
Author

Ok, thanks for the information - it makes sense that this is not configurable via HttpClient.
Do you know if this is a value that is tweaked for services in general, 21 seconds for a timeout seems way too long when working in a microservice environment.
Maybe changing the TcpMaxDataRetransmissions to 1 (or potentially zero) would help. Although I would be a little wary of doing this..

@timabell
Copy link

timabell commented Oct 2, 2018

For the googlers arriving here: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

@karelz
Copy link
Member

karelz commented Oct 2, 2018

I don't think there is anything left here for us to do.

@karelz karelz closed this as completed Oct 2, 2018
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Http question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

5 participants