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

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

View File

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

View File

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