start hyper server using with_graceful_shutdown()

Without, hyper keeps some futures running, and the server does not
correctly shutdown.
This commit is contained in:
Dietmar Maurer 2019-04-10 08:24:32 +02:00
parent 7f2078de59
commit 5f550fd99f
3 changed files with 15 additions and 8 deletions

View File

@ -61,6 +61,7 @@ fn run() -> Result<(), Error> {
|listener| { |listener| {
Ok(hyper::Server::builder(listener.incoming()) Ok(hyper::Server::builder(listener.incoming())
.serve(rest_server) .serve(rest_server)
.with_graceful_shutdown(server::shutdown_future())
.map_err(|e| eprintln!("server error: {}", e)) .map_err(|e| eprintln!("server error: {}", e))
) )
}, },
@ -77,7 +78,10 @@ fn run() -> Result<(), Error> {
if let Err(err) = init_result { if let Err(err) = init_result {
eprintln!("unable to start daemon - {}", err); eprintln!("unable to start daemon - {}", err);
} else { } else {
tokio::spawn(server); tokio::spawn(server.then(|_| {
log::info!("done - exit server");
Ok(())
}));
} }
Ok(()) Ok(())

View File

@ -91,9 +91,11 @@ fn run() -> Result<(), Error> {
// Filter out the Nones // Filter out the Nones
r r
}); });
Ok(hyper::Server::builder(connections) Ok(hyper::Server::builder(connections)
.serve(rest_server) .serve(rest_server)
.map_err(|e| eprintln!("server error: {}", e)) .with_graceful_shutdown(server::shutdown_future())
.map_err(|err| eprintln!("server error: {}", err))
) )
}, },
)?; )?;
@ -109,7 +111,10 @@ fn run() -> Result<(), Error> {
if let Err(err) = init_result { if let Err(err) = init_result {
eprintln!("unable to start daemon - {}", err); eprintln!("unable to start daemon - {}", err);
} else { } else {
tokio::spawn(server); tokio::spawn(server.then(|_| {
log::info!("done - exit server");
Ok(())
}));
} }
Ok(()) Ok(())

View File

@ -169,9 +169,7 @@ where
let mut reloader = Some(reloader); let mut reloader = Some(reloader);
let abort_future = server::shutdown_future().map_err(|_| {});
Ok(service Ok(service
.select(abort_future)
.map(move |_| { .map(move |_| {
crate::tools::request_shutdown(); // make sure we are in shutdown mode crate::tools::request_shutdown(); // make sure we are in shutdown mode
if server::is_reload_request() { if server::is_reload_request() {