Skip to content

Commit

Permalink
Fix #9052
Browse files Browse the repository at this point in the history
It's hard to reproduce this race condition going forward (e.g. it
depends on the precise order that goals are scheduled, but
https://github.com/roberth/nix-9052 current reproduces it, and this
fixes that.
  • Loading branch information
Ericson2314 committed Feb 24, 2025
1 parent d904921 commit 380b16e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/libstore/build/derivation-creation-and-realisation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ void DerivationCreationAndRealisationGoal::addWantedOutputs(const OutputsSpec &
{
/* If we already want all outputs, there is nothing to do. */
auto newWanted = wantedOutputs.union_(outputs);
bool needRestart = !newWanted.isSubsetOf(wantedOutputs);
bool moreWanted = !newWanted.isSubsetOf(wantedOutputs);
wantedOutputs = newWanted;

if (!needRestart)
if (!moreWanted)
return;

if (!optDrvPath)
// haven't started steps where the outputs matter yet
return;
worker.makeDerivationGoal(*optDrvPath, outputs, buildMode);
auto g = worker.makeDerivationGoal(*optDrvPath, outputs, buildMode);

if (!(upcast_goal(g)->exitCode == ecSuccess || upcast_goal(g)->exitCode == ecFailed || upcast_goal(g)->exitCode == ecNoSubstituters || upcast_goal(g)->exitCode == ecIncompleteClosure)) {
/* The original concrete goal has already finished and been
destroyed, so reset this variable and double-suspend */
concreteDrvGoal = g;
needsRestart = true;
}
}

Goal::Co DerivationCreationAndRealisationGoal::init()
Expand Down Expand Up @@ -108,8 +115,12 @@ Goal::Co DerivationCreationAndRealisationGoal::init()
g->preserveException = true;
}
optDrvPath = std::move(drvPath);
addWaitee(upcast_goal(concreteDrvGoal));
co_await Suspend{};

do {
needsRestart = false;
addWaitee(upcast_goal(concreteDrvGoal));
co_await Suspend{};
} while (needsRestart);

trace("outer build done");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ struct DerivationCreationAndRealisationGoal : public Goal
*/
OutputsSpec wantedOutputs;

/**
* Inner goal got recreated, need to wait again potentially.
*/
bool needsRestart = false;

/**
* The final output paths of the build.
*
Expand Down

0 comments on commit 380b16e

Please sign in to comment.