Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: properly catch and propogate panics in component handlers #3374

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions rust/worker/src/execution/operator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{system::ReceiverForMessage, utils::get_panic_message};
use crate::{system::ReceiverForMessage, utils::PanicError};
use async_trait::async_trait;
use chroma_error::{ChromaError, ErrorCodes};
use futures::FutureExt;
Expand Down Expand Up @@ -34,7 +34,7 @@ where
#[derive(Debug, Error)]
pub(super) enum TaskError<Err> {
#[error("Panic occurred while handling task: {0:?}")]
Panic(Option<String>),
Panic(PanicError),
#[error("Task failed with error: {0:?}")]
TaskFailed(#[from] Err),
}
Expand Down Expand Up @@ -149,13 +149,11 @@ where
}
}
Err(panic_value) => {
let panic_message = get_panic_message(panic_value);

match self
.reply_channel
.send(
TaskResult {
result: Err(TaskError::Panic(panic_message.clone())),
result: Err(TaskError::Panic(PanicError::new(panic_value))),
task_id: self.task_id,
},
None,
Expand All @@ -171,12 +169,6 @@ where
);
}
};

// Re-panic so the message handler can catch it
panic!(
"{}",
panic_message.unwrap_or("Unknown panic occurred in task".to_string())
);
}
};
}
Expand Down Expand Up @@ -296,6 +288,7 @@ mod tests {
let result = &results_guard.first().unwrap().result;

assert!(result.is_err());
matches!(result, Err(TaskError::Panic(Some(msg))) if msg == "MockOperator panicking");
let err = result.as_ref().unwrap_err();
assert!(err.to_string().contains("MockOperator panicking"));
}
}
7 changes: 4 additions & 3 deletions rust/worker/src/execution/orchestration/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::system::ChannelError;
use crate::system::ComponentContext;
use crate::system::ComponentHandle;
use crate::system::Handler;
use crate::utils::PanicError;
use async_trait::async_trait;
use chroma_blockstore::provider::BlockfileProvider;
use chroma_error::ChromaError;
Expand Down Expand Up @@ -143,8 +144,8 @@ impl ChromaError for GetSegmentWritersError {

#[derive(Error, Debug)]
pub enum CompactionError {
#[error("Panic running task: {0}")]
Panic(String),
#[error("Panic during compaction: {0}")]
Panic(#[from] PanicError),
#[error("FetchLog error: {0}")]
FetchLog(#[from] FetchLogError),
#[error("Partition error: {0}")]
Expand All @@ -167,7 +168,7 @@ where
{
fn from(value: TaskError<E>) -> Self {
match value {
TaskError::Panic(e) => CompactionError::Panic(e.unwrap_or_default()),
TaskError::Panic(e) => CompactionError::Panic(e),
TaskError::TaskFailed(e) => e.into(),
}
}
Expand Down
7 changes: 4 additions & 3 deletions rust/worker/src/execution/orchestration/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
},
},
system::{ChannelError, ComponentContext, ComponentHandle, Handler},
utils::PanicError,
};

use super::orchestrator::Orchestrator;
Expand All @@ -29,8 +30,8 @@ pub enum CountError {
FetchLog(#[from] FetchLogError),
#[error("Error running Count Record Operator: {0}")]
CountRecord(#[from] CountRecordsError),
#[error("Panic running task: {0}")]
Panic(String),
#[error("Panic: {0}")]
Panic(#[from] PanicError),
#[error("Error receiving final result: {0}")]
Result(#[from] RecvError),
}
Expand All @@ -53,7 +54,7 @@ where
{
fn from(value: TaskError<E>) -> Self {
match value {
TaskError::Panic(e) => CountError::Panic(e.unwrap_or_default()),
TaskError::Panic(e) => CountError::Panic(e),
TaskError::TaskFailed(e) => e.into(),
}
}
Expand Down
87 changes: 44 additions & 43 deletions rust/worker/src/execution/orchestration/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
},
},
system::{ChannelError, ComponentContext, ComponentHandle, Handler},
utils::PanicError,
};

use super::orchestrator::Orchestrator;
Expand All @@ -32,8 +33,8 @@ pub enum GetError {
Filter(#[from] FilterError),
#[error("Error running Limit Operator: {0}")]
Limit(#[from] LimitError),
#[error("Panic running task: {0}")]
Panic(String),
#[error("Panic: {0}")]
Panic(#[from] PanicError),
#[error("Error running Projection Operator: {0}")]
Projection(#[from] ProjectionError),
#[error("Error receiving final result: {0}")]
Expand All @@ -60,7 +61,7 @@ where
{
fn from(value: TaskError<E>) -> Self {
match value {
TaskError::Panic(e) => GetError::Panic(e.unwrap_or_default()),
TaskError::Panic(e) => e.into(),
TaskError::TaskFailed(e) => e.into(),
}
}
Expand All @@ -75,46 +76,46 @@ type GetResult = Result<GetOutput, GetError>;
///
/// # Pipeline
/// ```text
/// ┌────────────┐
/// │ │
/// │ on_start │
/// │ │
/// └──────┬─────┘
/// │
/// ▼
/// ┌────────────────────┐
/// │ │
/// │ FetchLogOperator │
/// │ │
/// └─────────┬──────────┘
/// │
/// ▼
/// ┌───────────────────┐
/// │ │
/// │ FilterOperator │
/// │ │
/// └─────────┬─────────┘
/// │
/// ▼
/// ┌─────────────────┐
/// │ │
/// │ LimitOperator │
/// │ │
/// └────────┬────────┘
/// │
/// ▼
/// ┌──────────────────────┐
/// │ │
/// │ ProjectionOperator │
/// │ │
/// └──────────┬───────────┘
/// │
/// ▼
/// ┌──────────────────┐
/// │ │
/// │ result_channel │
/// │ │
/// └──────────────────┘
/// ┌────────────┐
/// │ │
/// │ on_start │
/// │ │
/// └──────┬─────┘
/// │
/// ▼
/// ┌────────────────────┐
/// │ │
/// │ FetchLogOperator │
/// │ │
/// └─────────┬──────────┘
/// │
/// ▼
/// ┌───────────────────┐
/// │ │
/// │ FilterOperator │
/// │ │
/// └─────────┬─────────┘
/// │
/// ▼
/// ┌─────────────────┐
/// │ │
/// │ LimitOperator │
/// │ │
/// └────────┬────────┘
/// │
/// ▼
/// ┌──────────────────────┐
/// │ │
/// │ ProjectionOperator │
/// │ │
/// └──────────┬───────────┘
/// │
/// ▼
/// ┌──────────────────┐
/// │ │
/// │ result_channel │
/// │ │
/// └──────────────────┘
/// ```
#[derive(Debug)]
pub struct GetOrchestrator {
Expand Down
59 changes: 30 additions & 29 deletions rust/worker/src/execution/orchestration/knn_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
utils::distance_function_from_segment,
},
system::{ChannelError, ComponentContext, ComponentHandle, Handler},
utils::PanicError,
};

use super::orchestrator::Orchestrator;
Expand Down Expand Up @@ -57,8 +58,8 @@ pub enum KnnError {
KnnProjection(#[from] KnnProjectionError),
#[error("Error inspecting collection dimension")]
NoCollectionDimension,
#[error("Panic running task: {0}")]
Panic(String),
#[error("Panic: {0}")]
Panic(#[from] PanicError),
#[error("Error receiving final result: {0}")]
Result(#[from] RecvError),
#[error("Invalid distance function")]
Expand Down Expand Up @@ -92,7 +93,7 @@ where
{
fn from(value: TaskError<E>) -> Self {
match value {
TaskError::Panic(e) => KnnError::Panic(e.unwrap_or_default()),
TaskError::Panic(e) => e.into(),
TaskError::TaskFailed(e) => e.into(),
}
}
Expand All @@ -116,32 +117,32 @@ type KnnFilterResult = Result<KnnFilterOutput, KnnError>;
///
/// # Pipeline
/// ```text
/// ┌────────────┐
/// │ │
/// │ on_start │
/// │ │
/// └──────┬─────┘
/// │
/// ▼
/// ┌────────────────────┐
/// │ │
/// │ FetchLogOperator │
/// │ │
/// └─────────┬──────────┘
/// │
/// ▼
/// ┌───────────────────┐
/// │ │
/// │ FilterOperator │
/// │ │
/// └─────────┬─────────┘
/// │
/// ▼
/// ┌──────────────────┐
/// │ │
/// │ result_channel │
/// │ │
/// └──────────────────┘
/// ┌────────────┐
/// │ │
/// │ on_start │
/// │ │
/// └──────┬─────┘
/// │
/// ▼
/// ┌────────────────────┐
/// │ │
/// │ FetchLogOperator │
/// │ │
/// └─────────┬──────────┘
/// │
/// ▼
/// ┌───────────────────┐
/// │ │
/// │ FilterOperator │
/// │ │
/// └─────────┬─────────┘
/// │
/// ▼
/// ┌──────────────────┐
/// │ │
/// │ result_channel │
/// │ │
/// └──────────────────┘
/// ```
#[derive(Debug)]
pub struct KnnFilterOrchestrator {
Expand Down
17 changes: 13 additions & 4 deletions rust/worker/src/execution/orchestration/orchestrator.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use core::fmt::Debug;
use std::any::type_name;

use async_trait::async_trait;
use chroma_error::ChromaError;
use core::fmt::Debug;
use std::any::type_name;
use tokio::sync::oneshot::{self, error::RecvError, Sender};
use tracing::Span;

use crate::{
execution::{dispatcher::Dispatcher, operator::TaskMessage},
system::{ChannelError, Component, ComponentContext, ComponentHandle, System},
utils::PanicError,
};

#[async_trait]
pub trait Orchestrator: Debug + Send + Sized + 'static {
type Output: Send;
type Error: ChromaError + From<ChannelError> + From<RecvError>;
type Error: ChromaError + From<PanicError> + From<ChannelError> + From<RecvError>;

/// Returns the handle of the dispatcher
fn dispatcher(&self) -> ComponentHandle<Dispatcher>;
Expand Down Expand Up @@ -108,4 +108,13 @@ impl<O: Orchestrator> Component for O {
}
}
}

fn on_handler_panic(&mut self, panic_value: Box<dyn std::any::Any + Send>) {
let channel = self.take_result_channel();
let error = PanicError::new(panic_value);

if channel.send(Err(O::Error::from(error))).is_err() {
tracing::error!("Error reporting panic to {}", Self::name());
};
}
}
2 changes: 0 additions & 2 deletions rust/worker/src/system/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ pub enum RequestError {
SendError,
#[error("Failed to receive response")]
ReceiveError,
#[error("Message handler panicked")]
HandlerPanic(Option<String>),
}

impl ChromaError for RequestError {
Expand Down
Loading
Loading