Skip to content

Conversation

@xokdvium
Copy link
Contributor

@xokdvium xokdvium commented Nov 22, 2025

Motivation

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.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@xokdvium xokdvium requested a review from edolstra as a code owner November 22, 2025 14:36
@xokdvium xokdvium added the regression Something doesn't work anymore label Nov 22, 2025
@github-actions github-actions bot added the fetching Networking with the outside (non-Nix) world, input locking label Nov 22, 2025
@xokdvium
Copy link
Contributor Author

Root cause triaged with @roberth

@roberth
Copy link
Member

roberth commented Nov 22, 2025

libgit2 does implement a global packfile cache that should make this revert not the end of the world.

The git_mwindow__pack_cache shares the actual pack file handles, so you won't have duplicate file descriptors or duplicate memory mappings.

It does still perform:

  • Full directory listing of objects/pack/ (via direach)
  • Potentially loading multi-pack-index file

This has some overhead that would be nice to avoid somehow, but we have some added constraints

  • The mempack odb needs to be 1:1 with the packfile creation process
  • Not refreshing indexes might be a problem if we keep an increasingly stale copy of the pack index around (e.g. if we keep a pool of git_repository instances around or something)

More sharing is probably best achieved within the libgit2 codebase.

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave a comment that GitRepo is not thread safe

@xokdvium xokdvium force-pushed the revert-shared-tarball-cache branch from 1f33929 to 55bc46d Compare November 22, 2025 15:14
@xokdvium
Copy link
Contributor Author

Added a comment. Hopefully we won't step on this landmine any more in the future.

@Ericson2314
Copy link
Member

Ericson2314 commented Nov 22, 2025

I don't get how making it a global again prevents multi-threaded access? Also what's ODB corruption? My Google search did not answer that question.

@xokdvium
Copy link
Contributor Author

don't get how making it a global again prevents multi-threaded access?

It's not a global. openRepo returns a fresh GitRepo object. The only global there is the path to the tarball cache.

@xokdvium
Copy link
Contributor Author

@Ericson2314 has convinced me that rather than a full revert we can do a smaller diff change by just making getTarballCache open a new repo.

@xokdvium xokdvium force-pushed the revert-shared-tarball-cache branch from 55bc46d to 849a222 Compare November 22, 2025 19:07
@xokdvium xokdvium changed the title Revert "Move getTarballCache() into fetchers::Settings" libfetchers: Don't have a single shared tarball cache Nov 22, 2025
@xokdvium xokdvium requested a review from Ericson2314 November 22, 2025 19:08
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.
@xokdvium xokdvium force-pushed the revert-shared-tarball-cache branch from 849a222 to 385d7e7 Compare November 22, 2025 19:49
@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 23, 2025
Merged via the queue into master with commit d5d4baf Nov 23, 2025
21 checks passed
@Ericson2314 Ericson2314 deleted the revert-shared-tarball-cache branch November 23, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking regression Something doesn't work anymore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants