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

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

Closed
dbrgn opened this issue Aug 6, 2020 · 2 comments · Fixed by differs/Legends#5
Closed
Labels
A-http1 Area: HTTP/1 specific. C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: easy. A task that would be a great starting point for a new contributor.

Comments

@dbrgn
Copy link
Contributor

dbrgn commented Aug 6, 2020

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.

@seanmonstar
Copy link
Member

Currently the writing state just gets closed, here. Instead, end_body should probably be changed to return a crate::Result<()>, and that case should return an error that will shutdown the connection.

@seanmonstar seanmonstar added A-http1 Area: HTTP/1 specific. E-easy Effort: easy. A task that would be a great starting point for a new contributor. C-bug Category: bug. Something is wrong. This is bad! labels Aug 6, 2020
@dbrgn
Copy link
Contributor Author

dbrgn commented Aug 12, 2020

Thanks!

BenxiangGe pushed a commit to BenxiangGe/hyper that referenced this issue Jul 26, 2021
- update proto::h1::end_body to return Result<()>
- update Encoder::end to return Error(NotEof) only when there's Content-length left to be addressed

Closes hyperium#2263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-http1 Area: HTTP/1 specific. C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: easy. A task that would be a great starting point for a new contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants