Skip to content

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

@andreubotella

Description

@andreubotella
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions