From 5f550fd99f849385320103f6b874d9913cc83ca6 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 10 Apr 2019 08:24:32 +0200 Subject: [PATCH] start hyper server using with_graceful_shutdown() Without, hyper keeps some futures running, and the server does not correctly shutdown. --- src/bin/proxmox-backup-api.rs | 10 +++++++--- src/bin/proxmox-backup-proxy.rs | 11 ++++++++--- src/tools/daemon.rs | 2 -- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index 36d1eefe..a9a71f3e 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -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(()) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 9661cbe1..60f663ca 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -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(()) diff --git a/src/tools/daemon.rs b/src/tools/daemon.rs index e3becbd5..de679520 100644 --- a/src/tools/daemon.rs +++ b/src/tools/daemon.rs @@ -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() {