From 385d7e77bdbee44b5c7b66b53b1b8f096727ca0a Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sat, 22 Nov 2025 22:48:40 +0300 Subject: [PATCH] libfetchers: Don't have a single shared tarball cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This partially reverts commit bc6b9ce. This transformation is unsound and thread unsafe. Internal libgit2 structures must *never* be shared between threads. This causes internal odb corruption with e.g.: nix flake prefetch-inputs: error: … while fetching the input 'github:nixos/nixpkgs/89c2b2330e733d6cdb5eae7b899326930c2c0648?narHash=sha256-Stk9ZYRkGrnnpyJ4eqt9eQtdFWRRIvMxpNRf4sIegnw%3D' error: adding a file to a tree builder: failed to insert entry: invalid object specified - upload-image.sh error: … while fetching the input 'github:NixOS/nixpkgs/a8d610af3f1a5fb71e23e08434d8d61a466fc942?narHash=sha256-v5afmLjn/uyD9EQuPBn7nZuaZVV9r%2BJerayK/4wvdWA%3D' error: adding a file to a tree builder: failed to insert entry: invalid object specified - outline.nix double free or corruption (!prev) Thread 21 "nix" received signal SIGABRT, Aborted. --- src/libfetchers/git-utils.cc | 6 ++---- src/libfetchers/include/nix/fetchers/fetch-settings.hh | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 14504ee0b..4a7fc3d0d 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1334,10 +1334,8 @@ namespace fetchers { ref Settings::getTarballCache() const { - auto tarballCache(_tarballCache.lock()); - if (!*tarballCache) - *tarballCache = GitRepo::openRepo(std::filesystem::path(getCacheDir()) / "tarball-cache", true, true); - return ref(*tarballCache); + static auto repoDir = std::filesystem::path(getCacheDir()) / "tarball-cache"; + return GitRepo::openRepo(repoDir, true, true); } } // namespace fetchers diff --git a/src/libfetchers/include/nix/fetchers/fetch-settings.hh b/src/libfetchers/include/nix/fetchers/fetch-settings.hh index bddca3f9e..8cfa7f609 100644 --- a/src/libfetchers/include/nix/fetchers/fetch-settings.hh +++ b/src/libfetchers/include/nix/fetchers/fetch-settings.hh @@ -135,8 +135,6 @@ struct Settings : public Config private: mutable Sync> _cache; - - mutable Sync> _tarballCache; }; } // namespace nix::fetchers