From 5346b2bc6884ab71c1d0fc858f3b11484d01cbfb Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 18 Oct 2025 19:43:44 +0200 Subject: [PATCH] libstore: simplify worker child handling a bit we no longer need the optional wrapping. Change-Id: I742cca23753c6e0a97ada0b301bb42f442803ea8 --- lix/libstore/build/derivation-goal.cc | 55 ++++++++++----------- lix/libstore/build/derivation-goal.hh | 6 +-- lix/libstore/build/local-derivation-goal.cc | 16 ++++-- lix/libstore/build/local-derivation-goal.hh | 1 + 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index 799363154..57f7c5b99 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -1127,30 +1127,25 @@ try { buildResult.startTime = time(0); // inexact mcRunningBuilds = worker.runningBuilds.addTemporarily(1); - auto result = TRY_AWAIT(wrapChildHandler( - runPromise - .then( - // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) - [&](auto result) -> kj::Promise>> { - try { - std::shared_ptr remoteError; - if (result.getResult().isBad()) { - remoteError = - std::make_shared(from(result.getResult().getBad())); - logErrorInfo(remoteError->info().level, remoteError->info()); - } - // close the rpc connection to have the hook exit - hook->rpc = nullptr; - hook->wait(); - co_return TRY_AWAIT(buildDone(remoteError)); - } catch (...) { - co_return result::current_exception(); - } + auto result = TRY_AWAIT( + wrapChildHandler(runPromise.then([&](auto result) -> kj::Promise> { + try { + std::shared_ptr remoteError; + if (result.getResult().isBad()) { + remoteError = std::make_shared(from(result.getResult().getBad())); + logErrorInfo(remoteError->info().level, remoteError->info()); } - ) - )); + // close the rpc connection to have the hook exit + hook->rpc = nullptr; + hook->wait(); + return buildDone(remoteError); + } catch (...) { + return {result::current_exception()}; + } + })) + ); - co_return HookResult::Accept{std::move(*result)}; + co_return HookResult::Accept{std::move(result)}; } catch (...) { co_return result::current_exception(); } @@ -1248,8 +1243,8 @@ Goal::WorkResult DerivationGoal::tooMuchLogs() getName(), settings.maxLogSize)); } -kj::Promise>> -DerivationGoal::wrapChildHandler(kj::Promise>> handler) noexcept +kj::Promise> +DerivationGoal::wrapChildHandler(kj::Promise> handler) noexcept { if (respectsTimeouts() && settings.maxSilentTime != 0) { handler = handler.exclusiveJoin(monitorForSilence()); @@ -1260,7 +1255,7 @@ DerivationGoal::wrapChildHandler(kj::Promise>> AIO() .provider.getTimer() .afterDelay(settings.buildTimeout.get() * kj::SECONDS) - .then([this]() -> Result> { + .then([this]() -> Result { return timedOut( Error("%1% timed out after %2% seconds", name, settings.buildTimeout) ); @@ -1269,8 +1264,8 @@ DerivationGoal::wrapChildHandler(kj::Promise>> } if (logSink) { - handler = handler.exclusiveJoin(logSink->signal.promise.then( - [&](bool limitReached) -> kj::Promise>> { + handler = handler.exclusiveJoin( + logSink->signal.promise.then([&](bool limitReached) -> kj::Promise> { try { if (limitReached) { return {tooMuchLogs()}; @@ -1280,14 +1275,14 @@ DerivationGoal::wrapChildHandler(kj::Promise>> } catch (...) { return {result::current_exception()}; } - } - )); + }) + ); } return handler; } -kj::Promise>> DerivationGoal::monitorForSilence() noexcept +kj::Promise> DerivationGoal::monitorForSilence() noexcept { lastChildActivity = AIO().provider.getTimer().now(); diff --git a/lix/libstore/build/derivation-goal.hh b/lix/libstore/build/derivation-goal.hh index 59f548ef2..f6ef14811 100644 --- a/lix/libstore/build/derivation-goal.hh +++ b/lix/libstore/build/derivation-goal.hh @@ -309,9 +309,9 @@ struct DerivationGoal : public Goal protected: kj::TimePoint lastChildActivity = kj::minValue; - kj::Promise>> - wrapChildHandler(kj::Promise>> handler) noexcept; - kj::Promise>> monitorForSilence() noexcept; + kj::Promise> wrapChildHandler(kj::Promise> handler + ) noexcept; + kj::Promise> monitorForSilence() noexcept; WorkResult tooMuchLogs(); virtual std::string buildErrorContents(const std::string & exitMsg, bool diskFull); diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 67ce34b4b..0d259158f 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -281,9 +281,7 @@ retry: TRY_AWAIT(startBuilder()); mcRunningBuilds = worker.runningBuilds.addTemporarily(1); - if (auto error = TRY_AWAIT(wrapChildHandler(handleRawChildStream()))) { - co_return std::move(*error); - } + co_return TRY_AWAIT(wrapChildHandler(handleRawChild())); } catch (BuildError & e) { outputLocks.reset(); @@ -292,8 +290,6 @@ retry: report.permanentFailure = true; co_return report; } - - co_return co_await buildDone(); } catch (...) { co_return result::current_exception(); } @@ -2684,6 +2680,16 @@ StorePath LocalDerivationGoal::makeFallbackPath(const StorePath & path) Hash(HashType::SHA256), path.name()); } +kj::Promise> LocalDerivationGoal::handleRawChild() noexcept +try { + if (auto error = TRY_AWAIT(handleRawChildStream())) { + co_return std::move(*error); + } + co_return TRY_AWAIT(buildDone()); +} catch (...) { + co_return result::current_exception(); +} + kj::Promise>> LocalDerivationGoal::handleRawChildStream() noexcept try { diff --git a/lix/libstore/build/local-derivation-goal.hh b/lix/libstore/build/local-derivation-goal.hh index b705f7227..c1fac225f 100644 --- a/lix/libstore/build/local-derivation-goal.hh +++ b/lix/libstore/build/local-derivation-goal.hh @@ -324,6 +324,7 @@ protected: */ virtual Pid startChild(std::function openSlave); + kj::Promise> handleRawChild() noexcept; kj::Promise>> handleRawChildStream() noexcept; /**