From abcc816581c87321366bc7a96ac20a9fcc20dc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Tue, 10 Nov 2026 16:07:54 +0500 Subject: [PATCH] Stop: ask the world again when a shutdown request is lost A console shutdown request is sometimes lost, and the world then keeps running until the stop times out. While the world still runs and its console still answers after 15 s, the launcher asks again (twice at most); asking twice is harmless. Verified on a disposable repack with the first World::ShutdownServ call suppressed in a debugger: the second request stopped the world. Co-Authored-By: Claude Opus 5.5 --- crates/coa-core/src/launcher/services.rs | 37 +++++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/crates/coa-core/src/launcher/services.rs b/crates/coa-core/src/launcher/services.rs index 274b827..8b74b6b 100644 --- a/crates/coa-core/src/launcher/services.rs +++ b/crates/coa-core/src/launcher/services.rs @@ -268,6 +268,14 @@ fn owned_world(root: &Path) -> Result> { Ok(Some(world)) } +/// Ask the world's console for a graceful shutdown. False when the console is not this world's or does not answer. +fn ask_shutdown(root: &Path, cfg: &Settings) -> bool { + ready(root, "world", cfg.ra_port) + && crate::ra::Ra::connect_to(cfg.ra_port, &cfg.ra_username, &cfg.ra_password) + .and_then(|ra| ra.send_without_answer("server shutdown 1s 0")) + .is_ok() +} + /// Stop this folder's world without its console (unsaved progress since the last save is lost). fn stop_world_process(world: &ProcessIdentity) -> Result<()> { terminate(world).map_err(|_| Error::Invalid("Worldserver could not be stopped safely; its database was left running.".into()))?; @@ -290,18 +298,25 @@ pub fn force_stop_all(root: &Path, cfg: &Settings, progress: Progress) -> Result /// world leaves the shared database alone. pub fn stop_all(root: &Path, cfg: &Settings, progress: Progress) -> Result<()> { if let Some(world) = owned_world(root)? { - let asked = ready(root, "world", cfg.ra_port) - .then(|| crate::ra::Ra::connect_to(cfg.ra_port, &cfg.ra_username, &cfg.ra_password)) - .and_then(|r| r.ok()) - .map(|ra| ra.send_without_answer("server shutdown 1s 0")); - match asked { - Some(Ok(())) => progress("Graceful world shutdown requested."), - _ => { - progress("World console unavailable; stopping this repack's recorded world process."); - stop_world_process(&world)?; - } + if ask_shutdown(root, cfg) { + progress("Graceful world shutdown requested."); + } else { + progress("World console unavailable; stopping this repack's recorded world process."); + stop_world_process(&world)?; } - if !wait_stopped(&world, 90) { + // A console request can be lost (seen when a client disconnected at once). While the world still runs + // and its console still answers, it has not begun to stop: ask again. Asking twice is harmless. + let mut stopped = wait_stopped(&world, 15); + for _ in 0..2 { + if stopped { + break; + } + if ask_shutdown(root, cfg) { + progress("The world has not begun to stop; shutdown requested again."); + } + stopped = wait_stopped(&world, 15); + } + if !stopped && !wait_stopped(&world, 45) { return Err(Error::Invalid("Worldserver is still stopping; its database has been left running.".into())); } }