mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
Handle futures that panic on a threadpool (#216)
If a future panics from within the context of a thread pool, the pool should not be impacted. To do this, polling the future is wrapped with a catch_unwind. Extra care is taken to ensure that `thread::panicking()` is set from within the future's drop handle. Fixes #209
This commit is contained in:
@@ -386,3 +386,29 @@ fn busy_threadpool_is_not_idle() {
|
||||
|
||||
idle.wait().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_in_task() {
|
||||
let pool = ThreadPool::new();
|
||||
|
||||
struct Boom;
|
||||
|
||||
impl Future for Boom {
|
||||
type Item = ();
|
||||
type Error = ();
|
||||
|
||||
fn poll(&mut self) -> Poll<(), ()> {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Boom {
|
||||
fn drop(&mut self) {
|
||||
assert!(::std::thread::panicking());
|
||||
}
|
||||
}
|
||||
|
||||
pool.spawn(Boom);
|
||||
|
||||
pool.shutdown_on_idle().wait().unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user