Skip to content

Commit

Permalink
processGraph(): Don't throw ThreadPoolShutDown if there is an exception
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edolstra committed Jan 20, 2025
1 parent bcb92a5 commit bc70a99
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libutil/thread-pool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit bc70a99

Please sign in to comment.