From 6bea8e0e0802812bc384466e8740112515d72c4d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 19 Dec 2025 12:06:55 +0100 Subject: [PATCH] GitFileSystemObjectSink: Fix crash during interrupt --- src/libfetchers/git-utils.cc | 7 +++++++ src/libutil/include/nix/util/thread-pool.hh | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 4be46aee6..fc9fda850 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1094,6 +1094,13 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink { } + ~GitFileSystemObjectSinkImpl() + { + // Make sure the worker threads are destroyed before any state + // they're referring to. + workers.shutdown(); + } + struct Child; /// A directory to be written as a Git tree. diff --git a/src/libutil/include/nix/util/thread-pool.hh b/src/libutil/include/nix/util/thread-pool.hh index a07354146..61fea39b7 100644 --- a/src/libutil/include/nix/util/thread-pool.hh +++ b/src/libutil/include/nix/util/thread-pool.hh @@ -52,6 +52,12 @@ public: */ void process(); + /** + * Shut down all worker threads and wait until they've exited. + * Active work items are finished, but any pending work items are discarded. + */ + void shutdown(); + private: size_t maxThreads; @@ -72,8 +78,6 @@ private: std::condition_variable work; void doWork(bool mainThread); - - void shutdown(); }; /**