Skip to content

libfetchers: fix race in the Git filesystem object sink - #16088

Merged
Mic92 merged 2 commits into
NixOS:masterfrom
Mic92:fix-git-sink-ordering
Jul 2, 2026
Merged

Mic92 merged 2 commits into
NixOS:masterfrom
Mic92:fix-git-sink-ordering

Conversation

@Mic92

@Mic92 Mic92 commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

The sink built its tree structure from worker threads, after the blob bytes were written. Workers finish in any order, so for "foo" then "foo/bar" the "foo/bar" worker could run first and create "foo" as a directory instead of rejecting it as a file. Hence the flaky GitUtilsTest.sink_no_parent_dir.

Reserve each node synchronously, in order; workers only fill in the object ID afterwards.

Motivation

Context


Add 👍 to pull requests you find important.

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

The sink built its tree structure from worker threads, after the blob
bytes were written. Workers finish in any order, so for "foo" then
"foo/bar" the "foo/bar" worker could run first and create "foo" as a
directory instead of rejecting it as a file. Hence the flaky
GitUtilsTest.sink_no_parent_dir.

Reserve each node synchronously, in order; workers only fill in the
object ID afterwards.

Assisted-by: Claude:unspecified
@Mic92
Mic92 requested a review from edolstra as a code owner June 30, 2026 15:56
@github-actions github-actions Bot added the fetching Networking with the outside (non-Nix) world, input locking label Jun 30, 2026

@xokdvium xokdvium left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did notice this bug yesterday that my test uncovered. Thanks for doing this! It occurs to me that this code is very buggy and lacks good test coverage currently.

Would be nice if we also had tests for all the corner cases:

  • A non-directory parent foo when we write file/symlink/hardlink foo/bar. The test I added surfaced this particular case.
  • Replacing a file/directory/symlink/hardlink with another type of node. What if we try to replace a non-empty directory? Should that succeed/fail?

I'm not sure which behavior that we want. Probably not exactly matching libarchive which is very hard to understand - exactly when stuff gets unlinked/rejected (when unpacking to a filesystem), but a bit stricter if possible. (Or maybe match the behaviour prior to parallel implementation to be on the safer side).

Also, ideally we wouldn't do this as adjusting weird semantics of a FileSystemObjectSink and had a separate interface for unpacking a tarball (a TarSink, cc @Ericson2314).

@xokdvium

Copy link
Copy Markdown
Contributor

To be clear, this is certainly an improvement and untangling this mess probably should be done in a normal release cycle if possible, with proper tests and defined semantics. But fixing nondeterminism is a good start at least.

Comment thread src/libfetchers/git-utils.cc Resolved
Comment thread src/libfetchers/git-utils.cc Resolved
@xokdvium xokdvium self-assigned this Jun 30, 2026
@xokdvium

xokdvium commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Got started on cleaning this up, but discovered #16090 instead...

The parent-type check in the Git sink applies to every node kind, not
just regular files. Cover symlinks and hardlinks too.

Also give the child map a transparent comparator so lookups by
string_view no longer allocate a temporary std::string.

Assisted-by: Claude:unspecified
@xokdvium

xokdvium commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

I'm going to put an alternative setup which gets rids of mutexes altogether soonish. Would simplify things a lot

@Mic92
Mic92 added this pull request to the merge queue Jul 2, 2026

@xokdvium xokdvium left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Guess we can clean up later.

Merged via the queue into NixOS:master with commit fc7ac77 Jul 2, 2026
16 checks passed
@Mic92
Mic92 deleted the fix-git-sink-ordering branch July 2, 2026 20:07
@xokdvium xokdvium mentioned this pull request Nov 16, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants