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

error reading a body from connection: unexpected end of file #162

Closed
andreubotella opened this issue Dec 12, 2021 · 6 comments
Closed

error reading a body from connection: unexpected end of file #162

andreubotella opened this issue Dec 12, 2021 · 6 comments

Comments

@andreubotella
Copy link

andreubotella commented Dec 12, 2021

use anyhow::Error;
use hyper::{body::HttpBody, Client};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let https = hyper_rustls::HttpsConnectorBuilder::new()
        .with_native_roots()
        .https_or_http()
        .enable_http1()
        .build();
    let client = Client::builder().build::<_, hyper::Body>(https);
    let url = "https://wpt.live/resources/testharness.js".parse()?;
    let mut resp = client.get(url).await?;
    let mut read = 0usize;
    while let Some(chunk) = resp.body_mut().data().await {
        read += chunk?.len();
        println!("Reading {} bytes...", read);
    }
    println!("Finished! Read {} bytes in total.", read);
    Ok(())
}
[...]
Reading 172032 bytes...
Reading 180224 bytes...
Reading 182423 bytes...
Error: error reading a body from connection: unexpected end of file

Caused by:
    unexpected end of file

This error happens consistently. It seems to be related to the length of the response, because https://wpt.live/resources/testharnessreport.js (2268 bytes) triggers it, but https://wpt.live/resources/ (1975 bytes) doesn't. It also seems to be related to the specific TLS configuration of the server, since I can't replicate by proxying from Deno Deploy.

This error doesn't happen on hyper-rustls 0.22.0, so it might be related to rustls 0.20.

@djc
Copy link
Member

djc commented Dec 13, 2021

It might be useful to further minimize the reproduction case by getting hyper-rustls out of the loop; I expect this is caused by rustls/rustls#790 which is more or less intentional. If you want to further debug this (for example, using Wireshark and rustls configured with a KeyLogFile to enable SSLKEYLOGFILE) you could figure out if there's a difference between /resources/testharnessreport.js and /resources/ in whether they send a CloseNotify alert before closing their response stream.

@djc
Copy link
Member

djc commented Dec 13, 2021

Upon further reflection, if the above issue is indeed at fault I think the best fix might be inside hyper, where we could ignore UnexpectedEof errors only for requests/responses that are deemed complete.

@cpu
Copy link
Member

cpu commented Apr 2, 2024

if the above issue is indeed at fault I think the best fix might be inside hyper, where we could ignore UnexpectedEof errors only for requests/responses that are deemed complete.

I think we can consider this resolved w/ hyperium/h2#743

@cpu cpu closed this as completed Apr 2, 2024
@djc
Copy link
Member

djc commented Apr 2, 2024

(It's a little unclear if this might still be an issue for HTTP 1.)

@djc djc closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
@cpu
Copy link
Member

cpu commented Apr 2, 2024

this might still be an issue for HTTP 1

Ah, should we leave it open then?

@djc
Copy link
Member

djc commented Apr 2, 2024

Not sure -- probably okay to keep it closed, but let's keep in mind the nuance of the H2-only fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants