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:
Carl Lerche
2018-03-13 09:44:14 -07:00
committed by GitHub
parent 95899e007d
commit 96a542451d
2 changed files with 58 additions and 5 deletions
+26
View File
@@ -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();
}