-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
SocketsHttpHandler does not respect the Keep-Alive header #72958
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsRFC 2068 defines a For example:
which indicates that the connection should not be reused after idling for longer than 15 seconds, or for more than 100 requests.
We should consider honoring this header to improve compatibility with legacy servers.
|
Notes:
|
Keep-Alive isn't exactly unsupported by HTTP/1.1. Keep-Alive is called out explicitly in RFC 7230 Appendix A as something clients and servers may wish to stay compatible with:
https://httpwg.org/specs/rfc7230.html#rfc.section.A.1.2 The appendix goes on to mention a bunch of reasons that you may not want to send a request with a It makes perfect sense to me that browsers broadly support this considering it makes up for a big shortcoming in HTTP/1.1 where requests unnecessarily fail because there's a race condition when the client sends a request at the same moment server closes the connection due to its keep-alive timeout. In HttpClient scenarios, it might not be easy to retry such a request because it's unclear if the server processed the request before closing the connection in this case. Before .NET 6, both SocketsHttpHandler and Kestrel had 120s keep alive timeouts by default, but I updated these not to match to at least avoid this issue with newer versions of HttpClient and Kestrel. The timeout specified by the Keep-Alive response header solves this in a more widely compatible, more flexible way. I see no reason for SocketsHttpHandler not to use this information the same way browsers do.
We should do that. The
Again, it's a bit unfair to say that the connection doesn't support the semantics we expect. These responses are coming from Node.js web servers which very much do support HTTP/1.1. There's no reason SocketsHttpHandler cannot support these connections. It supports them already, so rejecting these connections would be a huge regression. However, it could support them better by taking into account the server's keep-alive timeout. I don't think SocketsHttpHandler should even validate that |
Triage: the fix should be simple enough, we should fix it in 7.0 |
RFC 2068 defines a
Keep-Alive
header that the server can send on HTTP/1.0 responses.For example:
which indicates that the connection should not be reused after idling for longer than 15 seconds, or for more than 100 requests.
SocketsHttpHandler
currently completely ignores this header.As a result, the server may respond to otherwise-valid requests with errors.
We should consider honoring this header to improve compatibility with legacy servers.
Browsers apparently broadly support this as well: browser compatibility.
The text was updated successfully, but these errors were encountered: