You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
the task was canceled when the http connection closed
One way to structure the description:
[short summary of the bug]
task canceled when client connection closed.
I tried this code:
async fn hello_world(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
println!("start sleep!!!!!");
tokio::time::sleep(tokio::time::Duration::from_secs(20)).await;
println!("end sleep!!!!");
Ok(Response::new("Hello, World".into()))
}
#[tokio::main]
async fn main() {
// We'll bind to 127.0.0.1:3000
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
// A `Service` is needed for every connection, so this
// creates one from our `hello_world` function.
let make_svc = make_service_fn(|_conn| async {
// service_fn converts our function into a `Service`
Ok::<_, Infallible>(service_fn(hello_world))
});
let server = Server::bind(&addr).serve(make_svc);
// Run this server for... forever!
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
}
[code sample that causes the bug]
i tried curl --location --request POST 'http://127.0.0.1:3030'.and then, abort request. the server side just print "start sleep!!!!!".not print "end sleep!!!!"
I expected to see this happen: [explanation]
i want to see print "end sleep!!!!"
Instead, this happened: [explanation]
The text was updated successfully, but these errors were encountered:
You can't make prevent that specific task from being canceled. But, depending on what you're actually trying to do, you have a few options:
If you just want to make sure something definitely happens, like cleaning up a resource or logging, you could create a custom type and impl Drop for it, and then let _guard = MyGuard;.
You could move the handler code into a task::spawn, which doesn't cancel normally, and have that spawned task return a Response. Something like:
Version
hyper 0.14.16
Platform
windows
Description
the task was canceled when the http connection closed
One way to structure the description:
[short summary of the bug]
task canceled when client connection closed.
I tried this code:
[code sample that causes the bug]
i tried
curl --location --request POST 'http://127.0.0.1:3030'
.and then, abort request. the server side just print "start sleep!!!!!".not print "end sleep!!!!"I expected to see this happen: [explanation]
i want to see print "end sleep!!!!"
Instead, this happened: [explanation]
The text was updated successfully, but these errors were encountered: