You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UnexpectedEof Error with hyper HTTP/2 Requests #1635
Some quick context: rustls returns UnexpectedEof from read if a connection is closed without the peer sending the close_notify TLS message. This is to prevent attackers from truncating connections in the middle of a message and changing their semantics.
Higher level protocols like HTTP/1 and HTTP/2 have their own framing that knows the length of a message (Content-Length, or HTTP/2 frames). So both servers and clients often don't worry so much about sending TLS close_notify before shutting down a TCP connection, which is fine. So long as the protocol is between messages there's no risk of a truncation attack.
But that does mean servers and clients need a little extra filtering on errors, particularly for idle connections.
I am guessing what's happening is this:
Curl makes a request, gets a response, and keeps the connection alive.
Curl finishes its list of URLs, and exits the process.
This closes the TCP connection (without explicitly sending close_notify).
Hyper is continually reading from the idle connection to see if more requests come in.
Hyper gets a TCP connection close.
But that is wrapped in a rustls reader, which turns it into an UnexpectedEof because there was no close_notify.
Hyper logs the UnexpectedEof.
If this hypothesis is right, the solution would be that Hyper should treat UnexpectedEof on an idle connection the same as it would treat a TCP connection close (i.e. an "expected" EOF), and not log an error.
On the rustls side, it's worth considering how we can make this more user-friendly. It's a frequent source of stubbed toes, and pretty mysterious to non-TLS experts. For instance we could have a field on ServerConfig / ClientConfig that says "application layer is fully framed." That would be applied to HTTP/2. It would also be applied to HTTP/1.1, provided that close-delimited bodies are disallowed, or in other words provided that one of Content-Length or Transfer-Encoding is required by the server.
We could also add a message to our UnexpectedEof errors that links to documentation on how to handle them.
There's been a trickle of frustrated Deno users in here: denoland/deno#13058.
I've suggested that ideally this should be fixed in hyper: rustls/hyper-rustls#162 but IIRC Sean didn't like that idea. Looks like Sean didn't remember that this had come up before.
the best fix might be inside hyper, where we could ignore UnexpectedEof errors only for requests/responses that are deemed complete
At a high level, at least, it makes sense to me :) I'll run it past Sean in the hyperium/hyper#3427 issue. Would you prefer me to close this out in the mean time? I'll be sure to follow back up here, either way.
Activity
jsha commentedon Nov 28, 2023
Some quick context: rustls returns UnexpectedEof from read if a connection is closed without the peer sending the
close_notifyTLS message. This is to prevent attackers from truncating connections in the middle of a message and changing their semantics.Higher level protocols like HTTP/1 and HTTP/2 have their own framing that knows the length of a message (Content-Length, or HTTP/2 frames). So both servers and clients often don't worry so much about sending TLS
close_notifybefore shutting down a TCP connection, which is fine. So long as the protocol is between messages there's no risk of a truncation attack.But that does mean servers and clients need a little extra filtering on errors, particularly for idle connections.
I am guessing what's happening is this:
close_notify).UnexpectedEofbecause there was noclose_notify.UnexpectedEof.If this hypothesis is right, the solution would be that Hyper should treat
UnexpectedEofon an idle connection the same as it would treat a TCP connection close (i.e. an "expected" EOF), and not log an error.On the rustls side, it's worth considering how we can make this more user-friendly. It's a frequent source of stubbed toes, and pretty mysterious to non-TLS experts. For instance we could have a field on
ServerConfig/ClientConfigthat says "application layer is fully framed." That would be applied to HTTP/2. It would also be applied to HTTP/1.1, provided that close-delimited bodies are disallowed, or in other words provided that one of Content-Length or Transfer-Encoding is required by the server.We could also add a message to our UnexpectedEof errors that links to documentation on how to handle them.
djc commentedon Nov 28, 2023
There's been a trickle of frustrated Deno users in here: denoland/deno#13058.
I've suggested that ideally this should be fixed in hyper: rustls/hyper-rustls#162 but IIRC Sean didn't like that idea. Looks like Sean didn't remember that this had come up before.
cablehead commentedon Nov 29, 2023
It looks like your advice @djc in rustls/hyper-rustls#162 is consistent with @jsha's above.
At a high level, at least, it makes sense to me :) I'll run it past Sean in the hyperium/hyper#3427 issue. Would you prefer me to close this out in the mean time? I'll be sure to follow back up here, either way.
cpu commentedon Dec 21, 2023
It doesn't seem like there are any changes to be made in this repo for this issue. I think pursuing fixes with Hyper is the correct path forward.