From 5641a5e9121d89ad970d78c3e7bf6016c5f5d917 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 27 Nov 2019 14:02:56 -0800 Subject: [PATCH] task: fix panic when dropping LocalSet it turns out that the `Scheduler::release` method on `LocalSet`'s `Scheduler` *is* called, when the `Scheduler` is dropped with tasks still running. Currently, that method is `unreachable!`, which means that dropping a `LocalSet` with tasks running will panic. This commit fixes the panic, by pushing released tasks to `pending_drop`. This is the same as `BasicScheduler`. Fixes #1842 Signed-off-by: Eliza Weisman --- tokio/src/task/local.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 8a401fe03b0..6d0adf31c0c 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -345,8 +345,9 @@ impl Schedule for Scheduler { } } - fn release(&self, _: Task) { - unreachable!("tasks should only be completed locally") + fn release(&self, task: Task) { + // This will be called when dropping the local runtime. + self.pending_drop.push(task); } fn release_local(&self, task: &Task) {