From a1b4bc7292c3349baef0c6270798f1a36b63516b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 20 Jan 2025 13:22:50 +0100 Subject: [PATCH] processGraph(): Don't throw ThreadPoolShutDown if there is an exception Fixes $ nix copy --derivation --to /tmp/nix /nix/store/... error: cannot enqueue a work item while the thread pool is shutting down The ThreadPoolShutDown exception was hiding the reason for the thread pool shut down, e.g. error: cannot add path '/nix/store/03sl46khd8gmjpsad7223m32ma965vy9-fix-static.patch' because it lacks a signature by a trusted key (cherry picked from commit a8c69cc907044565f9e43371663cc8315602b28a) --- src/libutil/thread-pool.hh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libutil/thread-pool.hh b/src/libutil/thread-pool.hh index dc056481a..4adc48657 100644 --- a/src/libutil/thread-pool.hh +++ b/src/libutil/thread-pool.hh @@ -150,8 +150,16 @@ void processGraph( } }; - for (auto & node : nodes) - pool.enqueue(std::bind(worker, std::ref(node))); + for (auto & node : nodes) { + try { + pool.enqueue(std::bind(worker, std::ref(node))); + } catch (ThreadPoolShutDown &) { + /* Stop if the thread pool is shutting down. It means a + previous work item threw an exception, so process() + below will rethrow it. */ + break; + } + } pool.process();