libstore: simplify worker child handling a bit
we no longer need the optional wrapping. Change-Id: I742cca23753c6e0a97ada0b301bb42f442803ea8
This commit is contained in:
@@ -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<Result<std::optional<WorkResult>>> {
|
||||
try {
|
||||
std::shared_ptr<Error> remoteError;
|
||||
if (result.getResult().isBad()) {
|
||||
remoteError =
|
||||
std::make_shared<Error>(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<Result<WorkResult>> {
|
||||
try {
|
||||
std::shared_ptr<Error> remoteError;
|
||||
if (result.getResult().isBad()) {
|
||||
remoteError = std::make_shared<Error>(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<Result<std::optional<Goal::WorkResult>>>
|
||||
DerivationGoal::wrapChildHandler(kj::Promise<Result<std::optional<WorkResult>>> handler) noexcept
|
||||
kj::Promise<Result<Goal::WorkResult>>
|
||||
DerivationGoal::wrapChildHandler(kj::Promise<Result<WorkResult>> handler) noexcept
|
||||
{
|
||||
if (respectsTimeouts() && settings.maxSilentTime != 0) {
|
||||
handler = handler.exclusiveJoin(monitorForSilence());
|
||||
@@ -1260,7 +1255,7 @@ DerivationGoal::wrapChildHandler(kj::Promise<Result<std::optional<WorkResult>>>
|
||||
AIO()
|
||||
.provider.getTimer()
|
||||
.afterDelay(settings.buildTimeout.get() * kj::SECONDS)
|
||||
.then([this]() -> Result<std::optional<WorkResult>> {
|
||||
.then([this]() -> Result<WorkResult> {
|
||||
return timedOut(
|
||||
Error("%1% timed out after %2% seconds", name, settings.buildTimeout)
|
||||
);
|
||||
@@ -1269,8 +1264,8 @@ DerivationGoal::wrapChildHandler(kj::Promise<Result<std::optional<WorkResult>>>
|
||||
}
|
||||
|
||||
if (logSink) {
|
||||
handler = handler.exclusiveJoin(logSink->signal.promise.then(
|
||||
[&](bool limitReached) -> kj::Promise<Result<std::optional<WorkResult>>> {
|
||||
handler = handler.exclusiveJoin(
|
||||
logSink->signal.promise.then([&](bool limitReached) -> kj::Promise<Result<WorkResult>> {
|
||||
try {
|
||||
if (limitReached) {
|
||||
return {tooMuchLogs()};
|
||||
@@ -1280,14 +1275,14 @@ DerivationGoal::wrapChildHandler(kj::Promise<Result<std::optional<WorkResult>>>
|
||||
} catch (...) {
|
||||
return {result::current_exception()};
|
||||
}
|
||||
}
|
||||
));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
kj::Promise<Result<std::optional<Goal::WorkResult>>> DerivationGoal::monitorForSilence() noexcept
|
||||
kj::Promise<Result<Goal::WorkResult>> DerivationGoal::monitorForSilence() noexcept
|
||||
{
|
||||
lastChildActivity = AIO().provider.getTimer().now();
|
||||
|
||||
|
||||
@@ -309,9 +309,9 @@ struct DerivationGoal : public Goal
|
||||
protected:
|
||||
kj::TimePoint lastChildActivity = kj::minValue;
|
||||
|
||||
kj::Promise<Result<std::optional<WorkResult>>>
|
||||
wrapChildHandler(kj::Promise<Result<std::optional<WorkResult>>> handler) noexcept;
|
||||
kj::Promise<Result<std::optional<WorkResult>>> monitorForSilence() noexcept;
|
||||
kj::Promise<Result<WorkResult>> wrapChildHandler(kj::Promise<Result<WorkResult>> handler
|
||||
) noexcept;
|
||||
kj::Promise<Result<WorkResult>> monitorForSilence() noexcept;
|
||||
WorkResult tooMuchLogs();
|
||||
|
||||
virtual std::string buildErrorContents(const std::string & exitMsg, bool diskFull);
|
||||
|
||||
@@ -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<Result<Goal::WorkResult>> 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<Result<std::optional<Goal::WorkResult>>>
|
||||
LocalDerivationGoal::handleRawChildStream() noexcept
|
||||
try {
|
||||
|
||||
@@ -324,6 +324,7 @@ protected:
|
||||
*/
|
||||
virtual Pid startChild(std::function<void()> openSlave);
|
||||
|
||||
kj::Promise<Result<WorkResult>> handleRawChild() noexcept;
|
||||
kj::Promise<Result<std::optional<WorkResult>>> handleRawChildStream() noexcept;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user