From a3865d6ba9fc61c31a3a4fb1794ba719ee8199c7 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 15 Jan 2021 21:05:00 +0200 Subject: [PATCH] index: wait with cleanup until work-queue is empty --- lib/index/mu-indexer.cc | 19 ++++++++++++++++++- lib/index/mu-scanner.hh | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/index/mu-indexer.cc b/lib/index/mu-indexer.cc index 34a0b316..fc227d2e 100644 --- a/lib/index/mu-indexer.cc +++ b/lib/index/mu-indexer.cc @@ -268,7 +268,24 @@ Indexer::Private::start(const Indexer::Config& conf) g_warning ("failed to start scanner"); goto leave; } - g_debug ("scanner finished"); + g_debug ("scanner finished with %zu file(s) in queue", + fq_.size()); + } + + + { + // now there may still be messages in the work queue... + // finish those, but only for a while. + const auto start{std::chrono::steady_clock::now()}; + while (!fq_.empty() && std::chrono::steady_clock::now() - start < 10s) { + std::this_thread::sleep_for(100ms); + } + } + + if (!fq_.empty()) { + g_warning ("scan takes too long; dropping %zu file(s) from queue", + fq_.size()); + fq_.clear(); } if (conf_.cleanup) { diff --git a/lib/index/mu-scanner.hh b/lib/index/mu-scanner.hh index 7f820a6b..3dc1fcca 100644 --- a/lib/index/mu-scanner.hh +++ b/lib/index/mu-scanner.hh @@ -65,7 +65,7 @@ public: ~Scanner(); /** - * Start the scan; this is a blocking call than run until + * Start the scan; this is a blocking call than runs until * finished or (from another thread) stop() is called. * * @return true if starting worked; false otherwise @@ -87,8 +87,8 @@ public: bool is_running() const; private: - struct Private; - std::unique_ptr priv_; + struct Private; + std::unique_ptr priv_; }; } // namespace Mu