From f85e091cb42ccf8125aaa93643055010db984244 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 7 Aug 2024 17:06:43 +0200 Subject: [PATCH 1/2] make sure the index scheduler never stops running --- index-scheduler/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index c9ea70bb8..5293c7140 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -612,7 +612,7 @@ impl IndexScheduler { #[cfg(test)] run.breakpoint(Breakpoint::Init); - run.wake_up.wait(); + run.wake_up.wait_timeout(std::time::Duration::from_secs(60)); loop { match run.tick() { From 1cc6ac089bf2cee3b3b2936e9c2e326e599d3f3a Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 7 Aug 2024 17:50:32 +0200 Subject: [PATCH 2/2] ensure the run function doesn't panic even if the tick function does --- index-scheduler/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index 5293c7140..d0eee03dc 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -35,6 +35,7 @@ pub type TaskId = u32; use std::collections::{BTreeMap, HashMap}; use std::io::{self, BufReader, Read}; use std::ops::{Bound, RangeBounds}; +use std::panic::{catch_unwind, AssertUnwindSafe}; use std::path::{Path, PathBuf}; use std::sync::atomic::Ordering::{self, Relaxed}; use std::sync::atomic::{AtomicBool, AtomicU32}; @@ -615,16 +616,21 @@ impl IndexScheduler { run.wake_up.wait_timeout(std::time::Duration::from_secs(60)); loop { - match run.tick() { - Ok(TickOutcome::TickAgain(_)) => (), - Ok(TickOutcome::WaitForSignal) => run.wake_up.wait(), - Err(e) => { + let ret = catch_unwind(AssertUnwindSafe(|| run.tick())); + match ret { + Ok(Ok(TickOutcome::TickAgain(_))) => (), + Ok(Ok(TickOutcome::WaitForSignal)) => run.wake_up.wait(), + Ok(Err(e)) => { tracing::error!("{e}"); // Wait one second when an irrecoverable error occurs. if !e.is_recoverable() { std::thread::sleep(Duration::from_secs(1)); } } + Err(_panic) => { + tracing::error!("Internal error: Unexpected panic in the `IndexScheduler::run` method."); + + } } } })