Skip to content

Commit 140aee3

Browse files
authored
Merge pull request #12235 from martinetd/add_multi_uaf
libutil: thread-pool: ensure threads finished on error
2 parents 01f5cf2 + afac093 commit 140aee3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/libstore/store-api.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ void Store::addMultipleToStore(
246246
act.progress(nrDone, pathsToCopy.size(), nrRunning, nrFailed);
247247
};
248248

249-
ThreadPool pool;
250-
251-
processGraph<StorePath>(pool,
249+
processGraph<StorePath>(
252250
storePathsToAdd,
253251

254252
[&](const StorePath & path) {
@@ -1028,12 +1026,10 @@ std::map<StorePath, StorePath> copyPaths(
10281026
}
10291027
auto pathsMap = copyPaths(srcStore, dstStore, storePaths, repair, checkSigs, substitute);
10301028

1031-
ThreadPool pool;
1032-
10331029
try {
10341030
// Copy the realisation closure
10351031
processGraph<Realisation>(
1036-
pool, Realisation::closure(srcStore, toplevelRealisations),
1032+
Realisation::closure(srcStore, toplevelRealisations),
10371033
[&](const Realisation & current) -> std::set<Realisation> {
10381034
std::set<Realisation> children;
10391035
for (const auto & [drvOutput, _] : current.dependentRealisations) {

src/libutil/thread-pool.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ private:
8383
*/
8484
template<typename T>
8585
void processGraph(
86-
ThreadPool & pool,
8786
const std::set<T> & nodes,
8887
std::function<std::set<T>(const T &)> getEdges,
8988
std::function<void(const T &)> processNode)
@@ -97,6 +96,10 @@ void processGraph(
9796

9897
std::function<void(const T &)> worker;
9998

99+
/* Create pool last to ensure threads are stopped before other destructors
100+
* run */
101+
ThreadPool pool;
102+
100103
worker = [&](const T & node) {
101104

102105
{

0 commit comments

Comments
 (0)