From 7bb0ea94723b27123fe9e0ce17637ce03250928b 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: Thu, 29 Oct 2026 08:33:11 +0500 Subject: [PATCH] Wait for slow CoA worlds before update rollback --- changelog.d/20261029-slow-world-startup.md | 7 +++ crates/coa-core/src/driver.rs | 40 ++++++----------- crates/coa-core/src/launcher_bridge.py | 13 +++++- tools/test_launcher_bridge.py | 50 +++++++++++++++++++++- 4 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 changelog.d/20261029-slow-world-startup.md diff --git a/changelog.d/20261029-slow-world-startup.md b/changelog.d/20261029-slow-world-startup.md new file mode 100644 index 0000000..8502b54 --- /dev/null +++ b/changelog.d/20261029-slow-world-startup.md @@ -0,0 +1,7 @@ +--- +area: manager +type: fixed +audience: admins +title: Slow server startup no longer triggers an early update rollback +--- +World startup now allows up to 25 minutes with either bot system and waits for both game and console ports within one deadline. Servers that stop during startup still fail immediately. diff --git a/crates/coa-core/src/driver.rs b/crates/coa-core/src/driver.rs index 6eff427..7e0eabd 100644 --- a/crates/coa-core/src/driver.rs +++ b/crates/coa-core/src/driver.rs @@ -31,36 +31,17 @@ impl Verb { } } - fn timeout(self, root: &Path) -> Duration { + fn timeout(self, _root: &Path) -> Duration { match self { - Verb::StartAll | Verb::StartWorld if squid_enabled(root) => Duration::from_secs(2700), - Verb::StartAll | Verb::StartWorld => Duration::from_secs(720), + // Includes database startup, optional bot provisioning and the shared 25-minute + // world/console wait in launcher_bridge.py, even for older installed scripts. + Verb::StartAll | Verb::StartWorld => Duration::from_secs(3600), Verb::StartMysql => Duration::from_secs(360), Verb::StopAll => Duration::from_secs(240), } } } -fn squid_enabled(root: &Path) -> bool { - let active = root.join("Core/configs/modules/playerbots.conf"); - let path = if active.exists() { - active - } else { - root.join("Core/configs/modules/playerbots.conf.dist") - }; - std::fs::read(path) - .ok() - .and_then(|bytes| crate::config::parser::ConfFile::parse_bytes(&bytes).ok()) - .is_some_and(|config| { - config.get("AiPlayerbot.Enabled").is_none_or(|value| { - !matches!( - value.trim().trim_matches('"').to_ascii_lowercase().as_str(), - "0" | "false" | "no" | "off" - ) - }) - }) -} - #[derive(Debug, Clone, Serialize)] pub struct DriverOutcome { pub ok: bool, @@ -230,6 +211,13 @@ fn run_inner(root: &Path, verb: Verb, validating_update: bool) -> Result (st.success(), st.code()), None => (false, None), @@ -604,7 +592,7 @@ mod tests { } #[test] - fn large_squid_provisioning_has_time_to_finish_without_extending_shutdown() { + fn slow_world_startup_has_time_with_either_bot_system_without_extending_shutdown() { let folder = tempfile::tempdir().unwrap(); let modules = folder.path().join("Core/configs/modules"); std::fs::create_dir_all(&modules).unwrap(); @@ -615,7 +603,7 @@ mod tests { .unwrap(); assert_eq!( Verb::StartAll.timeout(folder.path()), - Duration::from_secs(2700) + Duration::from_secs(3600) ); assert_eq!( Verb::StopAll.timeout(folder.path()), @@ -624,7 +612,7 @@ mod tests { std::fs::write(modules.join("playerbots.conf"), "AiPlayerbot.Enabled = 0\n").unwrap(); assert_eq!( Verb::StartWorld.timeout(folder.path()), - Duration::from_secs(720) + Duration::from_secs(3600) ); assert_eq!( Verb::StartMysql.timeout(folder.path()), diff --git a/crates/coa-core/src/launcher_bridge.py b/crates/coa-core/src/launcher_bridge.py index e5bdadf..e31d47c 100644 --- a/crates/coa-core/src/launcher_bridge.py +++ b/crates/coa-core/src/launcher_bridge.py @@ -1,5 +1,6 @@ import runpy import sys +import time from pathlib import Path script = sys.argv[1] @@ -7,10 +8,20 @@ sys.path.insert(0, str(Path(script).resolve().parent)) sys.argv = sys.argv[1:] launcher = runpy.run_path(script, run_name="coa_manager_launcher") original_wait = launcher["wait_ready"] +world_deadline = None def wait_ready(name, port, seconds=180): - return original_wait(name, port, max(seconds, 300) if name == "mysql" else seconds) + global world_deadline + if name == "mysql": + seconds = max(seconds, 300) + elif name == "world": + # Both game and console listeners belong to one startup, including on old repacks. + # Ordinary CoA worlds can load slowly too; this must not depend on SQUID. + if world_deadline is None: + world_deadline = time.monotonic() + max(seconds, 1500) + seconds = max(0, world_deadline - time.monotonic()) + return original_wait(name, port, seconds) launcher["start_mysql"].__globals__["wait_ready"] = wait_ready diff --git a/tools/test_launcher_bridge.py b/tools/test_launcher_bridge.py index e48b1be..5706900 100644 --- a/tools/test_launcher_bridge.py +++ b/tools/test_launcher_bridge.py @@ -3,6 +3,7 @@ import runpy import sys import tempfile import unittest +import time from unittest.mock import patch BRIDGE = pathlib.Path(__file__).resolve().parents[1] / 'crates/coa-core/src/launcher_bridge.py' @@ -103,7 +104,54 @@ def main(): wait_ready('world', 23456, 180) wait_ready('mysql', 12345, 900) ''') - self.assertEqual(result['launcher']['calls'], [('mysql', 300), ('world', 180), ('mysql', 900)]) + calls = result['launcher']['calls'] + self.assertEqual(calls[0], ('mysql', 300)) + self.assertEqual(calls[2], ('mysql', 900)) + self.assertEqual(calls[1][0], 'world') + self.assertAlmostEqual(calls[1][1], 1500, delta=1) + + def world_start(self, *, game_at=420, console_at=480, dies_at=None, requested=180): + clock = [0.0] + def sleep(seconds): clock[0] += seconds + body = f''' +import time +calls = [] +dies_at = {dies_at!r} +def wait_ready(name, port, seconds=180): + until = time.monotonic() + seconds + while time.monotonic() < until: + if dies_at is not None and time.monotonic() >= dies_at: + raise RuntimeError('world stopped during startup') + if time.monotonic() >= ({game_at!r} if port == 1 else {console_at!r}): + calls.append(port) + return + time.sleep(0.5) + raise RuntimeError('world is still starting') +def start_mysql(): pass +def main(): + wait_ready('world', 1, {requested}) + wait_ready('world', 2, {requested}) +''' + with patch('time.monotonic', side_effect=lambda: clock[0]), patch('time.sleep', side_effect=sleep): + result = self.launch('start-all', body) + return clock[0], result['launcher']['calls'] + + def test_legacy_coa_world_waits_for_both_ports_after_three_minutes(self): + elapsed, calls = self.world_start() + self.assertEqual((elapsed, calls), (480, [1, 2])) + + def test_console_wait_shares_the_world_deadline(self): + with self.assertRaisesRegex(RuntimeError, 'still starting'): + self.world_start(game_at=1490, console_at=1510) + self.assertEqual(self.launcher['calls'], [1]) + + def test_world_exit_is_reported_without_waiting_out_the_extended_budget(self): + with self.assertRaisesRegex(RuntimeError, 'stopped during startup'): + self.world_start(dies_at=12) + self.assertEqual(self.launcher['calls'], []) + + def test_existing_longer_world_timeout_is_preserved(self): + self.assertEqual(self.world_start(game_at=1600, console_at=1700, requested=1800), (1700, [1, 2])) def test_stop_dispatch_does_not_prepare_or_start_anything(self): result = self.launch('stop-all', '''