From 7fc6fd244e3a1f67d41fe1a546c6cc319fee42d8 Mon Sep 17 00:00:00 2001 From: Arne Beer Date: Sun, 23 Jun 2024 12:38:28 +0200 Subject: [PATCH] fix: Stack-overflow during shutdown --- pueue/src/daemon/process_handler/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pueue/src/daemon/process_handler/mod.rs b/pueue/src/daemon/process_handler/mod.rs index 3d3952f..7da428a 100644 --- a/pueue/src/daemon/process_handler/mod.rs +++ b/pueue/src/daemon/process_handler/mod.rs @@ -17,9 +17,13 @@ pub mod start; /// We don't have to pause any groups, as no new tasks will be spawned during shutdown anyway. /// Any groups with queued tasks, will be automatically paused on state-restoration. pub fn initiate_shutdown(settings: &Settings, state: &mut LockedState, shutdown: Shutdown) { - state.shutdown = Some(shutdown); - - self::kill::kill(settings, state, TaskSelection::All, false, None); + // Only start shutdown if we aren't already in one. + // Otherwise, we might end up with an endless recursion as `kill` might fail and initiate shutdown + // once again. + if state.shutdown.is_none() { + state.shutdown = Some(shutdown); + self::kill::kill(settings, state, TaskSelection::All, false, None); + } } /// This is a small wrapper around the real platform dependant process handling logic