Skip to content

Commit bbefd6a

Browse files
committed
tests: Add test for panic mid-'spawn_many'
Due to Mutex poisoning, this causes the executor's inner mutex to become poisoned. So this makes it so the poison is ignored on drop. Signed-off-by: John Nunley <[email protected]>
1 parent d96068a commit bbefd6a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a> Executor<'a> {
391391
impl Drop for Executor<'_> {
392392
fn drop(&mut self) {
393393
if let Some(state) = self.state.get() {
394-
let mut active = state.active.lock().unwrap();
394+
let mut active = state.active.lock().unwrap_or_else(|e| e.into_inner());
395395
for w in active.drain() {
396396
w.wake();
397397
}

tests/drop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ fn drop_finished_task_and_then_drop_executor() {
121121
assert_eq!(DROP.load(Ordering::SeqCst), 1);
122122
}
123123

124+
#[test]
125+
fn iterator_panics_mid_run() {
126+
let ex = Executor::new();
127+
128+
let panic = std::panic::catch_unwind(|| {
129+
let mut handles = vec![];
130+
ex.spawn_many(
131+
(0..50).map(|i| if i == 25 { panic!() } else { future::ready(i) }),
132+
&mut handles,
133+
)
134+
});
135+
assert!(panic.is_err());
136+
}
137+
124138
struct CallOnDrop<F: Fn()>(F);
125139

126140
impl<F: Fn()> Drop for CallOnDrop<F> {

0 commit comments

Comments
 (0)