From 86407a59b36473b078a96979adc5a619a5f1ac80 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 25 Nov 2019 17:09:26 +0100 Subject: [PATCH] MDEV-16264 - Fix assertion `m_queue.empty() && !m_tasks_running' in tpool::task_group destructor This particular assertion happened when shutting down Innodb IO.IO shutdown properly waits for all IOs to finish However there is a race condition - right after releasing last IO slot and before decrementing task count in group, pending_io_count will be 0, but tasks_running will be 1, leading to assertion. The fix is to make task_group destructor to wait for last running task to finish. --- tpool/task_group.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tpool/task_group.cc b/tpool/task_group.cc index ec9988ded6e..b52fe7c0f67 100644 --- a/tpool/task_group.cc +++ b/tpool/task_group.cc @@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/ #include #include #include +#ifndef _WIN32 +#include // usleep +#endif namespace tpool { task_group::task_group(unsigned int max_concurrency) : @@ -79,6 +82,18 @@ namespace tpool task_group::~task_group() { - assert(m_queue.empty() && !m_tasks_running); + std::unique_lock lk(m_mtx); + assert(m_queue.empty()); + + while (m_tasks_running) + { + lk.unlock(); +#ifndef _WIN32 + usleep(1000); +#else + Sleep(1); +#endif + lk.lock(); + } } }