Skip to content

Conversation

@wolfgangwalther
Copy link
Contributor

Running (parallel?) nix in nix can lead to multiple instances trying to create the state directories and failing on the createSymlink step, because the link already exists.

replaceSymlink is 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-vet in 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.

Running parallel nix in nix can lead to multiple instances trying to
create the state directories and failing on the `createSymlink` step,
because the link already exists.

`replaceSymlink` is already idempotent, so let's use that.

Resolves NixOS#2706
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Jun 17, 2025
@edolstra edolstra enabled auto-merge June 17, 2025 08:47
@edolstra edolstra closed this Jun 17, 2025
auto-merge was automatically disabled June 17, 2025 08:53

Pull request was closed

@edolstra edolstra reopened this Jun 17, 2025
@edolstra edolstra enabled auto-merge June 17, 2025 08:53
@edolstra edolstra merged commit bb32fcd into NixOS:master Jun 17, 2025
13 checks passed
@wolfgangwalther wolfgangwalther deleted the race-state-creation branch June 17, 2025 10:21
lf- pushed a commit to lix-project/lix that referenced this pull request Jun 26, 2025
Running (parallel?) nix in nix can lead to multiple instances trying
to create the state directories and failing on the createSymlink step,
because the link already exists.

`replaceSymlink` is already idempotent, so let's use that.

See also:
- NixOS/nix#13368
- NixOS/nix#2706

Change-Id: I7fadd0ce3c1ffcebc9d281c00e5b49c12af3d50b
@roberth roberth added backports created Does not require attention and can be filtered away backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch labels Jul 30, 2025
mergify bot added a commit that referenced this pull request Jul 31, 2025
…3368

libstore: fix race condition when creating state directories (backport #13368)
mergify bot added a commit that referenced this pull request Jul 31, 2025
…3368

libstore: fix race condition when creating state directories (backport #13368)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backports created Does not require attention and can be filtered away store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating missing state directories if they don't already exist is racey

3 participants