From 7506d680ac540f39944c2a9f573900c5b1e4a023 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 11 Aug 2024 21:53:29 +0200 Subject: [PATCH] libstore: don't ignore max-build-log-size for ssh-ng Change-Id: Ieab14662bea6e6f5533325f0e945147be998f9a2 --- src/libstore/build/derivation-goal.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 291504a0f..17b6afbb2 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -1278,17 +1278,21 @@ bool DerivationGoal::isReadDesc(int fd) Goal::WorkResult DerivationGoal::handleChildOutput(int fd, std::string_view data) { + auto tooMuchLogs = [&] { + killChild(); + return done( + BuildResult::LogLimitExceeded, {}, + Error("%s killed after writing more than %d bytes of log output", + getName(), settings.maxLogSize)); + }; + // local & `ssh://`-builds are dealt with here. auto isWrittenToLog = isReadDesc(fd); if (isWrittenToLog) { logSize += data.size(); if (settings.maxLogSize && logSize > settings.maxLogSize) { - killChild(); - return done( - BuildResult::LogLimitExceeded, {}, - Error("%s killed after writing more than %d bytes of log output", - getName(), settings.maxLogSize)); + return tooMuchLogs(); } for (auto c : data) @@ -1317,7 +1321,13 @@ Goal::WorkResult DerivationGoal::handleChildOutput(int fd, std::string_view data const auto type = (*json)["type"]; const auto fields = (*json)["fields"]; if (type == resBuildLogLine) { - (*logSink)((fields.size() > 0 ? fields[0].get() : "") + "\n"); + const std::string logLine = + (fields.size() > 0 ? fields[0].get() : "") + "\n"; + logSize += logLine.size(); + if (settings.maxLogSize && logSize > settings.maxLogSize) { + return tooMuchLogs(); + } + (*logSink)(logLine); } else if (type == resSetPhase && ! fields.is_null()) { const auto phase = fields[0]; if (! phase.is_null()) {