From 3339103ff5425a1fc49b357c148634e81b168f5f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 22 Jun 2023 17:52:31 +0000 Subject: [PATCH] fix --- .../src/runtime/scheduler/multi_thread/worker.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tokio/src/runtime/scheduler/multi_thread/worker.rs b/tokio/src/runtime/scheduler/multi_thread/worker.rs index dc0bd98b1..5ff2a3db3 100644 --- a/tokio/src/runtime/scheduler/multi_thread/worker.rs +++ b/tokio/src/runtime/scheduler/multi_thread/worker.rs @@ -703,17 +703,22 @@ impl Worker { // We consumed all work in the queues and will start searching for work. core.stats.end_processing_scheduled_tasks(&mut self.stats); + if !cx.defer.borrow().is_empty() { + // We are deferring tasks, so poll the resource driver and schedule + // the deferred tasks. + core = try_task_new_batch!(self, self.park_yield(cx, core)); + + panic!("what happened to the deferred tasks? 🤔"); + } + while !self.is_shutdown { // Search for more work, this involves trying to poll the resource // driver, steal from other workers, and check the global queue // again. core = try_task_new_batch!(self, self.search_for_work(cx, core)); - if !cx.defer.borrow().is_empty() { - core = try_task_new_batch!(self, self.park_yield(cx, core)); - } else { - core = try_task_new_batch!(self, self.park(cx, core)); - } + debug_assert!(cx.defer.borrow().is_empty()); + core = try_task_new_batch!(self, self.park(cx, core)); } // Shutting down, drop any deferred tasks