libstore: fix race condition when creating state directories #13368
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Running (parallel?) nix in nix can lead to multiple instances trying to create the state directories and failing on the
createSymlinkstep, because the link already exists.replaceSymlinkis already idempotent, so let's use that.Resolves #2706
I only see this race appearing in Nixpkgs' CI right now, for example https://github.com/NixOS/nixpkgs/actions/runs/15426171510/job/43413501065. It only happens very infrequently. I tried reproducing locally, by just running
nix-build ci -A nixpkgs-vetin a loop, but didn't succeed, so far. I'm running Lix locally, but that shouldn't make a difference, the relevant code is the same. I assume I can't reproduce, because I'd need to start from an empty cache, but I'm not sure.Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.