Return an error instead of panicking on shutdown (#5530)

This commit is contained in:
teor 2022-11-02 12:43:13 +10:00 committed by GitHub
parent e380676937
commit c5e6adc87a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -240,8 +240,16 @@ where
{
match Pin::new(worker_handle).poll(cx) {
Poll::Ready(Ok(())) => return Poll::Ready(Err(self.get_worker_error())),
Poll::Ready(task_panic) => {
task_panic.expect("unexpected panic in batch worker task")
Poll::Ready(Err(task_cancelled)) if task_cancelled.is_cancelled() => {
tracing::warn!(
"batch task cancelled: {task_cancelled}\n\
Is Zebra shutting down?"
);
return Poll::Ready(Err(task_cancelled.into()));
}
Poll::Ready(Err(task_panic)) => {
std::panic::resume_unwind(task_panic.into_panic());
}
Poll::Pending => {}
}