From 76125f8eb1705ac3230acf134961d6e87da144f3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 29 Aug 2025 13:15:35 -0400 Subject: [PATCH] Get rid of `Finally` in `DerivationBuilderImpl::unprepareBuild` Calling `reset` on this `std::optional` field of `DerivationBuilderImpl` is also what the (automatically created) destructor of `DerivationBuilderImpl` will do. We should be making sure that the derivation builder is cleaned up by the goal anyways, and if we do that, then this `Finally` is no longer needed. --- src/libstore/build/derivation-building-goal.cc | 3 +++ src/libstore/unix/build/derivation-builder.cc | 8 -------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libstore/build/derivation-building-goal.cc b/src/libstore/build/derivation-building-goal.cc index 6aab48a80..4497a6070 100644 --- a/src/libstore/build/derivation-building-goal.cc +++ b/src/libstore/build/derivation-building-goal.cc @@ -769,9 +769,11 @@ Goal::Co DerivationBuildingGoal::tryToBuild() try { builtOutputs = builder->unprepareBuild(); } catch (BuilderFailureError & e) { + builder.reset(); outputLocks.unlock(); co_return doneFailure(fixupBuilderFailureErrorMessage(std::move(e))); } catch (BuildError & e) { + builder.reset(); outputLocks.unlock(); // Allow selecting a subset of enum values # pragma GCC diagnostic push @@ -796,6 +798,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild() co_return doneFailure(std::move(e)); } { + builder.reset(); StorePathSet outputPaths; for (auto & [_, output] : builtOutputs) { // for sake of `bmRepair` diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index 60509560d..f837efe5a 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -484,14 +484,6 @@ bool DerivationBuilderImpl::prepareBuild() SingleDrvOutputs DerivationBuilderImpl::unprepareBuild() { - // FIXME: get rid of this, rely on RAII. - Finally releaseBuildUser([&]() { - /* Release the build user at the end of this function. We don't do - it right away because we don't want another build grabbing this - uid and then messing around with our output. */ - buildUser.reset(); - }); - /* Since we got an EOF on the logger pipe, the builder is presumed to have terminated. In fact, the builder could also have simply have closed its end of the pipe, so just to be sure,