From 20ca59114a0493df699a74b3d472e7afe1bdf921 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 21 Sep 2018 19:20:41 +0200 Subject: [PATCH] threadpool: impl Drop for Queue (#649) We need to drain the queue when dropping, or else those `Arc`s will be leaked. Fixes #542 --- ci/tsan | 1 + tokio-threadpool/src/task/queue.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/ci/tsan b/ci/tsan index 853736c22..65d65eff2 100644 --- a/ci/tsan +++ b/ci/tsan @@ -29,4 +29,5 @@ race:crossbeam_deque*steal # original pop operation will fail due to the ABA guard, but tsan still picks # up the access on the next pointer. race:Backup::next_sleeper +race:Backup::set_next_sleeper race:WorkerEntry::set_next_sleeper diff --git a/tokio-threadpool/src/task/queue.rs b/tokio-threadpool/src/task/queue.rs index 7782ac009..546b8c50f 100644 --- a/tokio-threadpool/src/task/queue.rs +++ b/tokio-threadpool/src/task/queue.rs @@ -115,3 +115,13 @@ impl Queue { Poll::Inconsistent } } + +impl Drop for Queue { + fn drop(&mut self) { + loop { + if let Poll::Empty = unsafe { self.poll() } { + break + } + } + } +}