Repository navigation
Closed
hyperium/h2
#743Labels
C-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!
Description
Version
hyper = { version = "1.0.1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
http-body-util = "0.1"
hyper-util = { version = "0.1.1", features = ["full"] }
tokio-rustls = "0.24.1"
rustls-pemfile = "1.0.4"
rustls = "0.21.9"
Platform
Darwin m1 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103 arm64
Description
When making successful HTTP/2 requests over TLS , the following server logs an UnexpectedEof error for each request:
tokio::task::spawn(async move {
if let Err(err) = hyper::server::conn::http2::Builder::new(
hyper_util::rt::tokio::TokioExecutor::new(),
)
.serve_connection(io, service_fn(hello))
.await
{
println!("Error serving connection: {:?}", err);
}
});I tried this code:
https://gist.github.com/cablehead/e24990e364ecb3e6028d5978acd0c1c9
I performed a request using:
% curl -v -k --http2 https://localhost:3000
* Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN: server accepted h2
* Server certificate:
* subject: CN=localhost
* start date: Nov 17 19:09:27 2023 GMT
* expire date: Nov 16 19:09:27 2024 GMT
* issuer: CN=localhost
* SSL certificate verify result: self signed certificate (18), continuing anyway.
* using HTTP/2
* h2 [:method: GET]
* h2 [:scheme: https]
* h2 [:authority: localhost:3000]
* h2 [:path: /]
* h2 [user-agent: curl/8.1.2]
* h2 [accept: */*]
* Using Stream ID: 1 (easy handle 0x132814200)
> GET / HTTP/2
> Host: localhost:3000
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/2 200
< date: Sun, 19 Nov 2023 17:36:02 GMT
< content-length: 13
<
* Connection #0 to host localhost left intact
Hello, World!%This successfully returns "Hello world" from the server. However, the server prints out the following error on every successful request:
Error serving connection: hyper::Error(Io, Kind(UnexpectedEof))
Using the http1 builder with the same TLS wrapper does not exhibit this behavior, and neither does HTTP/2 without the TLS wrapper.
The expected behavior is that no error should be logged when a request completes successfully.
Metadata
Metadata
Assignees
Labels
C-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!
Activity
seanmonstar commentedon Nov 20, 2023
Hm, is this a regression? Did it happen in 0.14?
cablehead commentedon Nov 20, 2023
I'm pretty sure I've seen it with 0.14 too: it's easier to tease out with v1, as concerns are better separated now(!). Lemme try to reproduce...
cablehead commentedon Nov 20, 2023
Yeah, it's not a regression. This is a reproduction with 0.14:
https://github.com/cablehead/hyper-with-tls/tree/main/hyper-0.14-rustls
seanmonstar commentedon Nov 20, 2023
Well that's good at least. Is it only with curl? Or do other clients also see this? Are you able to enable
h2s logs to see what it was expecting?cablehead commentedon Nov 21, 2023
I've put up the repro for v1, and turned on tracing here: https://github.com/cablehead/hyper-with-tls/tree/main/hyper-1.0.1-rustls
These are the logs from
curl -v -k --http2 https://localhost:3000cablehead commentedon Nov 21, 2023
The first attempt with Safari (macOS), I got:
Error accepting TLS connection: Custom { kind: UnexpectedEof, error: "tls handshake eof" }(so a slightly different error) 3 times, the first time I made a request (it'd be requesting additional assets): but then subsequent refreshes don't log that error. I tried clearing the cache for localhost, and still can't get it to log that again. Switching to private mode, I was able to get it to log that again, on first request, but now even entering private mode again, refreshes are served cleanly.seanmonstar commentedon Nov 21, 2023
I tried searching
h2forUnexpectedEof, and the only place it exists is unrelated.tokio-utilalso doesn't return it. It could be coming fromrustls(here, whenh2checks if there's any more frames, that will eventually check apoll_readon the TLS stream.Does this happen with native-tls?
It could also be that curl in this case is terminating the connection differently than Safari.
Gelbpunkt commentedon Nov 21, 2023
I'm seeing pretty much the same thing with rustls + hyper v1, but I'm getting
hyper::Error(Shutdown, Os { code: 107, kind: NotConnected, message: "Transport endpoint is not connected" })instead ofUnexpectedEof.curling the server always produces this, using Firefox to access it works fine and does not produce any errors.Gelbpunkt commentedon Nov 21, 2023
Here's the tracing logs for my issue: https://gist.github.com/Gelbpunkt/b0fb2063d198cbae23b93b678065f3c1
I can reproduce
UnexpectedEofon HTTP/2, "Transport endopint is not connected" happens on HTTP/1.1[-]UnexpectedEof Error on HTTP/2 Requests with Rustls and Hyper v1[/-][+]UnexpectedEof Error on HTTP/2 Requests with Rustls[/+]seanmonstar commentedon Nov 21, 2023
Just to reiterate, it was noticed earlier in the thread that this seems to occur with hyper v0.14 as well (so I've adjusted the title).
Is this something new with rustls? Or with curl?
kayabaNerve commentedon Nov 22, 2023
Apologies if this is just noise, yet when using hyper 0.14 + hyper-rustls on a per-connection basis (so not with the connection-pooling Client API), I would have sockets which worked a few ms prior suddenly error when making a new request over HTTP1.
was a log snippet I saved.
I was unsure if this was my fault, as it worked fine with the Client API (though I did check my connecting-driving re: async and Drop), or hyper's, or the server I was connecting to. Now seeing this issue, I feel this anecdote may be relevant.
cablehead commentedon Nov 22, 2023
Interesting.
I'll knock up a sample that uses
native-tlsto see. Might just take a couple of dayscablehead commentedon Nov 24, 2023
@Gelbpunkt I haven't come across any issues with HTTP1 + rustls yet. Do you have a small repro?
cablehead commentedon Nov 24, 2023
This is a quick sample with hyper v1 + native-tls:
https://github.com/cablehead/hyper-with-tls/tree/main/hyper-1.0.1-native-tls
(i've merged the above v1 + rustls and v0.14 + rustls samples under this same repo and updated the links to them above)
With the
native-tlssample, the connection closes cleanly after:@seanmonstar I'm thinking my next best step is to close this issue, and create a new one against
rustls?seanmonstar commentedon Nov 24, 2023
It'd reasonable to assume the evidence points there. If after reporting there, new evidence says it's in hyper, we can dig further over here!
Replace rustls with boring-ssl
Replace rustls with boring-ssl
cablehead commentedon Nov 29, 2023
Returning with new information :)
I raised the issue with rustls here: rustls/rustls#1635
@jsha added some good context:
And he's since opened a PR to add this documentation: https://github.com/rustls/rustls/pull/1637/files#diff-015212fe8ccad176046e9d830f1db1e9ddde16d0e922f3817f72c07e587c9e17R36
If I'm understanding things correctly, it seems like the bug ultimately lies with curl. TLS clients are expected to send a
close_notify. Practically though, it seems likely that, in addition to curl, many HTTP clients may just rely on the higher level HTTP/2 message framing.@djc suggests:
Which may be the most pragmatic thing. What are your thoughts @seanmonstar? If you think it's reasonable, I could take a shot at a PR for it. And in that case, any easy pointers your could throw my way would be appreciated :)
Given we don't see it with HTTP/1.1, I wonder: could hyper already be doing this if all outstanding requests are closed for HTTP/1.1 🤔
Replace rustls with boring-ssl
Replace rustls with boring-ssl
Replace rustls with boring-ssl