diff --git a/proxmox-rest-server/src/daemon.rs b/proxmox-rest-server/src/daemon.rs index 2ff20246..d96c18fd 100644 --- a/proxmox-rest-server/src/daemon.rs +++ b/proxmox-rest-server/src/daemon.rs @@ -274,7 +274,9 @@ where let finish_future = match future::select(server_future, shutdown_future).await { Either::Left((_, _)) => { - crate::request_shutdown(); // make sure we are in shutdown mode + if !crate::shutdown_requested() { + crate::request_shutdown(); // make sure we are in shutdown mode + } None } Either::Right((_, server_future)) => Some(server_future), diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs index 697e2242..9c2dbb08 100644 --- a/proxmox-rest-server/src/lib.rs +++ b/proxmox-rest-server/src/lib.rs @@ -1,4 +1,5 @@ use std::os::unix::io::RawFd; +use std::sync::atomic::{Ordering, AtomicBool}; use anyhow::{bail, format_err, Error}; use nix::unistd::Pid; @@ -92,18 +93,17 @@ pub fn our_ctrl_sock() -> String { ctrl_sock_from_pid(*PID) } -static mut SHUTDOWN_REQUESTED: bool = false; +static SHUTDOWN_REQUESTED: AtomicBool = AtomicBool::new(false); pub fn request_shutdown() { - unsafe { - SHUTDOWN_REQUESTED = true; - } + println!("request_shutdown"); + SHUTDOWN_REQUESTED.store(true, Ordering::SeqCst); crate::server_shutdown(); } #[inline(always)] pub fn shutdown_requested() -> bool { - unsafe { SHUTDOWN_REQUESTED } + SHUTDOWN_REQUESTED.load(Ordering::SeqCst) } pub fn fail_on_shutdown() -> Result<(), Error> {