hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.08k stars 1.55k forks source link

Hyper server hangs when handling a request from a client on the same host (not necessarily the same process) #3611

Closed haydnv closed 3 months ago

haydnv commented 3 months ago

Version hyper 1.2 futures 0.3 http_body_util 0.1 hyper_util 0.1 tokio 1.36 with the macros, net, and rt-multi-thread features

Platform Linux x86_64

Description A Hyper server task hangs at http1::Builder::new().serve_connection(io, service), where io is a hyper_util::TokioIo wrapping a tokio::net::TcpStream and service is constructed with hyper::service::service_fn. Here is a minimal reproducible example: https://gist.github.com/haydnv/9ed45169963a61c8a18aca341b3b3044

I expect that the test client will receive a "Hello, World!" response from the test server exactly once, but what actually happens is that the server task hangs at http1::Builder::serve_connection. Let me know if I can provide any more information to help debug this issue.

seanmonstar commented 3 months ago

The hang comes from L86. You're awaiting the client connection, and trying to send a request after that. When the client connection future completes, that means the connection is closed. You usually want to spawn the connection into a new task.

haydnv commented 3 months ago

Got it, thanks!