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

Graceful shutdown hangs when I use a Chromium based browser #1100

Open
czy-29 opened this issue May 8, 2024 · 1 comment
Open

Graceful shutdown hangs when I use a Chromium based browser #1100

czy-29 opened this issue May 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@czy-29
Copy link

czy-29 commented May 8, 2024

Version
v0.3.7

Platform
64-bit Windows 10

Description
When I use a Chromium based browser, the graceful shutdown hangs.
The minimal reproducible code is as follows:

use std::net::Ipv4Addr;
use tokio::{signal::ctrl_c, sync::oneshot};
use warp::Filter;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();

    let (shutdown_s, shutdown_r) = oneshot::channel();
    let graceful_shutdown = async move {
        shutdown_r.await.ok();
    };
    let routes = warp::any().map(|| "hello");
    let (_, fut) = warp::serve(routes)
        .try_bind_with_graceful_shutdown((Ipv4Addr::LOCALHOST, 8080), graceful_shutdown)?;
    let routine = tokio::spawn(fut);

    tracing::info!("started!");

    ctrl_c().await?;
    shutdown_s.send(()).ok();
    Ok(routine.await?)
}

Then, when you open a Chromium-based browser (such as Edge), visit 127.0.0.1:8080, and then press ctrl-c in the terminal, graceful shutdown will hang until the entire browser is completely closed (if you have other tabs, closing the current tab will have no effect, and graceful shutdown will remain stuck).

Typical log output for this code is as follows:

2024-05-08T14:45:49.179092Z  INFO repr: started!
2024-05-08T14:45:51.538331Z DEBUG hyper::proto::h1::io: parsed 15 headers
2024-05-08T14:45:51.538971Z DEBUG hyper::proto::h1::conn: incoming body is empty
2024-05-08T14:45:51.539646Z DEBUG hyper::proto::h1::io: flushed 121 bytes
2024-05-08T14:45:51.607208Z DEBUG hyper::proto::h1::io: parsed 13 headers
2024-05-08T14:45:51.607625Z DEBUG hyper::proto::h1::conn: incoming body is empty
2024-05-08T14:45:51.608183Z DEBUG hyper::proto::h1::io: flushed 121 bytes
2024-05-08T14:45:53.140266Z DEBUG hyper::server::shutdown: signal received, starting graceful shutdown

Then it will stay stuck here until the browser is completely closed.

I tried Axum before and found that they also have the same problem: tokio-rs/axum#2611
But it seems that their problem is caused by a bug in hyper-util:
hyperium/hyper#3576
hyperium/hyper-util#101

After I patched hyper-util, their problems were solved. However, patch hyper-util has no effect on warp, and the problem still exists after patching.
So for warp, I hope we can also fix this bug, or if there are any ready-made hox-fix or workaround mitigation solutions, I hope we can provide them, thank you!

@czy-29
Copy link
Author

czy-29 commented May 30, 2024

It seems that if hyper is upgraded to 1.x, this issue will be solved.
Therefore, this issue can be linked to this issue: #1088

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant