mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
ensure the run function doesn't panic even if the tick function does
This commit is contained in:
parent
8f6a98df07
commit
442d06dce7
@ -35,6 +35,7 @@ pub type TaskId = u32;
|
|||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::io::{self, BufReader, Read};
|
use std::io::{self, BufReader, Read};
|
||||||
use std::ops::{Bound, RangeBounds};
|
use std::ops::{Bound, RangeBounds};
|
||||||
|
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::atomic::Ordering::{self, Relaxed};
|
use std::sync::atomic::Ordering::{self, Relaxed};
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU32};
|
use std::sync::atomic::{AtomicBool, AtomicU32};
|
||||||
@ -615,16 +616,21 @@ impl IndexScheduler {
|
|||||||
run.wake_up.wait_timeout(std::time::Duration::from_secs(60));
|
run.wake_up.wait_timeout(std::time::Duration::from_secs(60));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match run.tick() {
|
let ret = catch_unwind(AssertUnwindSafe(|| run.tick()));
|
||||||
Ok(TickOutcome::TickAgain(_)) => (),
|
match ret {
|
||||||
Ok(TickOutcome::WaitForSignal) => run.wake_up.wait(),
|
Ok(Ok(TickOutcome::TickAgain(_))) => (),
|
||||||
Err(e) => {
|
Ok(Ok(TickOutcome::WaitForSignal)) => run.wake_up.wait(),
|
||||||
|
Ok(Err(e)) => {
|
||||||
tracing::error!("{e}");
|
tracing::error!("{e}");
|
||||||
// Wait one second when an irrecoverable error occurs.
|
// Wait one second when an irrecoverable error occurs.
|
||||||
if !e.is_recoverable() {
|
if !e.is_recoverable() {
|
||||||
std::thread::sleep(Duration::from_secs(1));
|
std::thread::sleep(Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(_panic) => {
|
||||||
|
tracing::error!("Internal error: Unexpected panic in the `IndexScheduler::run` method.");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user