Repository navigation
libfetchers: fix race in the Git filesystem object sink - #16088
Conversation
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
xokdvium
left a comment
There was a problem hiding this comment.
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
foowhen we write file/symlink/hardlinkfoo/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).
|
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. |
|
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
|
I'm going to put an alternative setup which gets rids of mutexes altogether soonish. Would simplify things a lot |
xokdvium
left a comment
There was a problem hiding this comment.
Guess we can clean up later.
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.