From 88dc0ccb9e0c38df33bf758304b9482bee53b1f5 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 18:37:17 +0800 Subject: [PATCH] fix: stop persistent queue before URL workers --- crates/xmedia-bot/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/xmedia-bot/src/main.rs b/crates/xmedia-bot/src/main.rs index 00ed2e7..0919328 100644 --- a/crates/xmedia-bot/src/main.rs +++ b/crates/xmedia-bot/src/main.rs @@ -263,18 +263,19 @@ async fn main() { .await; } - // Graceful stop (Ctrl+C / SIGTERM): stop the sweep, notify the admin, - // drain the queue. Bounded: a worker mid-download (30 s timeout) or a - // long ugoira encode must not hold the shutdown hostage forever. + // Graceful stop (Ctrl+C / SIGTERM): stop the queue first so no new + // persistent task is leased while the URL workers drain. The two drains + // share the bounded shutdown budget; URL work may legitimately outlive it, + // but the queue must not be left running until process exit. log::info!("Stopping bot"); const SHUTDOWN_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); let shutdown = async { let _ = stop_tx.send(true); + TASK_QUEUE.stop().await; handlers::stop_url_workers().await; if let Some(admin) = CONFIG.admin_ids.first() { let _ = bot.send_message(ChatId(*admin), "Shutting down...").await; } - TASK_QUEUE.stop().await; }; if tokio::time::timeout(SHUTDOWN_TIMEOUT, shutdown) .await