Skip to content

Sending a streamed non-chunked request will hang when body sender is dropped early #2263

Closed
differs/Legends
#5
@dbrgn

Description

@dbrgn

When sending a streaming request (using Body::channel) without content-length, the request terminates when dropping the Sender. But when a content-length is set, dropping the Sender before all bytes are sent will result in a request being stuck.

use hyper::{self, Body};

#[tokio::main]
async fn main() {
    let (tx, body) = Body::channel();
    let req = hyper::Request::builder()
        .uri("http://httpbin.org/post")
        .method(hyper::Method::POST)
        .header("content-length", 1337)
        .body(body)
        .unwrap();
    let client = hyper::Client::new();
    std::mem::drop(tx);
    println!("Sending request...");
    let res = client.request(req).await.unwrap();
    println!("Response: {:?}", res);
}

The example above will terminate when the content-length header is removed, but like this it hangs until the server closes the connection.

On the other hand, when explicitly aborting the sender using tx.abort(), the request will terminate with an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-http1Area: HTTP/1 specific.C-bugCategory: bug. Something is wrong. This is bad!E-easyEffort: easy. A task that would be a great starting point for a new contributor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions