fix: catch panics of named tasks (#22386)

This commit is contained in:
Arsenii Kulikov
2026-02-20 02:32:02 +04:00
committed by GitHub
parent 48122300d7
commit b6bcd7e6bd

View File

@@ -5,7 +5,7 @@
//! named task, like a 1-thread thread pool keyed by name.
use dashmap::DashMap;
use std::thread;
use std::{panic::AssertUnwindSafe, thread};
use tokio::sync::{mpsc, oneshot};
type BoxedTask = Box<dyn FnOnce() + Send + 'static>;
@@ -26,7 +26,7 @@ impl WorkerThread {
.name(name.to_string())
.spawn(move || {
while let Some(task) = rx.blocking_recv() {
task();
let _ = std::panic::catch_unwind(AssertUnwindSafe(task));
}
})
.unwrap_or_else(|e| panic!("failed to spawn worker thread {name:?}: {e}"));