-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
SocketException with HttpClient #29038
Comments
This may be hard issue to track (just setting expectations). Did you see similar issue in .NET Core 2.1? Or did you not use 2.1 at all? |
Also, please link the similar issues you mentioned above. |
Have you ruled out the possiblility that you are running into an actual resource exhaustion issue? The error code you're seeing comes from the underlying socket implementation (WinSock), and indicates that the connection request to the server was unable to be completed within 21 seconds. The most common scenario here would be that the server or client is under high load, and cannot complete the connection within that timeframe. Do you have any logs that indicate the server is actually responding to the connection request when this error occurs? |
So this is now seen to occur even under low load scenarios. |
That's a potentially useful datapoint. This isn't actionable without more information though. We need either a repro or a thorough set of logs that shows the issue really is in the sockets layer. |
I am not able to repro it in dev/test environment. The issue seems to be visible only in production. This is what I observe when the exception occurs:
|
That call stack doesn't look unusual to me. It is consistent with what you would see if an actual connection establish timeout were occuring, as mentioned in the first part of the exception message:
We need to be able to rule out that case before doing a deeper investigation here. There are a few approaches you can take there. The best is obviously to provide a repro. Alternatively you can try collecting network traces (e.g. wireshark or tcpdump) on the client that show the connection succeeding, or not being initiated at all. Be aware that the default configuration there captures all network traffic, which can potentially contain sensitive information in a production service. |
Is this still problem @snehashankar? You mentioned "socket exhaustion issue" but do you have any evidence? #29327 and #28582 fail with different symptoms but they may give you some good background reading. |
am facing the same exception. Please see my below and let me know if you need any additional info. startup.cs
httpclientHelper.cs |
Also, is this running on Windows or Linux on Azure? |
You should also collect Wireshark packet dump to see that that the server did or did not respond. If it didn't this exception is correct and there is nothing wrong with HttpClient. |
This is running on Azure AppService P2V2 plan with 20 instances |
You're right, sorry. I mis-read that line thinking it was turning off 'Keep-Alive'. |
Using 'Keep-Alive' semantics is on by default for HTTP/1.1. It isn't strictly necessary to include any 'Connection: Keep-Alive' request header when using HTTP/1.1. It is assumed to be 'Keep-Alive' by default. So, I'm curious why adding this request header changed anything for you. Is it because your HTTP requests are not HTTP/1.1 by default? Are you going through an HTTP/1.0 proxy perhaps? |
Triage: Looks like we do not have actionable info. Closing. |
We have seen a similar behavior in our service. Upon further investigation we have observed that under load HttpClient was using up all available sockets. That's related to the change between netfx and netcore where in netfx HttpClient was using |
I am currently working on a bug fix related to the HttpClient socket exhaustion issue. The SocketException message which I receive is as follows:
System.Net.Sockets.SocketException: Message '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', ErrorCode 10060, HResult -2147467259, NativeErrorCode 10060, SocketErrorCode TimedOut, Source 'System.Private.CoreLib'
This issue occurs at high load scenarios with dotnet core 2.2. I am trying hard to repro this since 2 weeks now with similar or higher load. But unfortunately, there’s no luck.
We are using HttpClientFactory and injecting the HttpClient.
I did see some similar issues reported on this platform, and I am pretty much following what looks correct.
Any pointers on this (and the repro) would be highly appreciable.
The text was updated successfully, but these errors were encountered: