From a11f80c44cfcc72f922cf2c567c771a3ab316444 Mon Sep 17 00:00:00 2001 From: Weijia Jiang Date: Thu, 21 Sep 2023 00:56:10 +0800 Subject: [PATCH] fix: dead lock --- tokio/src/runtime/task/list.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tokio/src/runtime/task/list.rs b/tokio/src/runtime/task/list.rs index 7736abd331a..f28b902a3cc 100644 --- a/tokio/src/runtime/task/list.rs +++ b/tokio/src/runtime/task/list.rs @@ -127,6 +127,7 @@ impl OwnedTasks { let mut lock = self.lists[task_id.0 as usize & (self.grain - 1) as usize].lock(); // check close flag if self.closed.load(Ordering::Acquire) { + drop(lock); task.shutdown(); return None; } @@ -159,13 +160,15 @@ impl OwnedTasks { self.closed.store(true, Ordering::Release); for i in start..self.grain as usize + start { loop { - let task = match self.lists[i & (self.grain - 1) as usize].lock().pop_back() { + let mut lock = self.lists[i & (self.grain - 1) as usize].lock(); + let task = match lock.pop_back() { Some(task) => { self.count.fetch_sub(1, Ordering::Relaxed); task } None => break, }; + drop(lock); task.shutdown(); } }