From a628f214a1177bff086edd2525eda5591f1799a1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 7 Feb 2022 18:03:53 +0200 Subject: [PATCH] index: fix thread-sanitizer issue Need a lock to access workers_; --- lib/index/mu-indexer.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/index/mu-indexer.cc b/lib/index/mu-indexer.cc index 72a12a0a..2dfa17d5 100644 --- a/lib/index/mu-indexer.cc +++ b/lib/index/mu-indexer.cc @@ -298,11 +298,17 @@ Indexer::Private::scan_worker() // now there may still be messages in the work queue... // finish those; this is a bit ugly; perhaps we should // handle SIGTERM etc. - if (!todos_.empty()) - g_debug("process %zu remaining message(s) with %zu worker(s)", todos_.size(), - workers_.size()); - while (!todos_.empty()) - std::this_thread::sleep_for(100ms); + + if (!todos_.empty()) { + const auto workers_size = std::invoke([this] { + std::lock_guard lock{w_lock_}; + return workers_.size(); + }); + g_debug("process %zu remaining message(s) with %zu worker(s)", + todos_.size(), workers_size); + while (!todos_.empty()) + std::this_thread::sleep_for(100ms); + } store_.commit();