Adding graceful shutdown for hyper Server connection

Following the hyper graceful_shudown.rs example I've ran into a issue with adding graceful_shutdown() on the connection.

I am using hyper_util::server::conn::auto::Builder and the serve_connection returns the Connection which should have the graceful_shutdown method available.

So, when starting the connection via, there are no as_mut() methods available, nor graceful_shutdown.


let builder = hyper_util::server::conn::auto::Builder::new(TokioExecutor::new());
let conn = builder.service_connection(TokioIo::new(stream, my_service);
pin!(conn);

clippy also suggests placing conn in Box::new, which allows the .as_mut() , but still not graceful_shutdown() method available.

Same happens when trying to use hyper::server::conn::http1 instead of the hyper_util::server::conn::auto.

What I previously had was the standard:


if let Err(e) = Builder::new(TokioExecutor::new()).serve_connection(TokioIo::new(stream), my_service).await {
 // Handle the erorrs here
// ....
}

I don't really know what to do and where to look at this point, does anyone have a working example/reference somewhere, or any idea how to help with this.

Thank you !

I think the as_mut() method in the example code refers to Pin::as_mut(), not Box::as_mut(), the clippy suggestion is misleading in this case. after all, it cannot understand what the user's intention is, it can only search for matches based on the method names.

according to the document, yes it should have the method graceful_shutdown(). but you didn't show any code, it's impossible to figure out where the error is. if you want get people's help to find the error. please at least provide the code that causes the error.

Thank you for the answer, the problem was with IDE using the wrong pin macro, tokio::pin was needed to be used.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.