libstore: don't ignore max-build-log-size for ssh-ng

Change-Id: Ieab14662bea6e6f5533325f0e945147be998f9a2
This commit is contained in:
eldritch horrors 2024-08-11 21:53:29 +02:00
parent 38f550708d
commit 7506d680ac

View file

@ -1278,17 +1278,21 @@ bool DerivationGoal::isReadDesc(int fd)
Goal::WorkResult DerivationGoal::handleChildOutput(int fd, std::string_view data) 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. // local & `ssh://`-builds are dealt with here.
auto isWrittenToLog = isReadDesc(fd); auto isWrittenToLog = isReadDesc(fd);
if (isWrittenToLog) if (isWrittenToLog)
{ {
logSize += data.size(); logSize += data.size();
if (settings.maxLogSize && logSize > settings.maxLogSize) { if (settings.maxLogSize && logSize > settings.maxLogSize) {
killChild(); return tooMuchLogs();
return done(
BuildResult::LogLimitExceeded, {},
Error("%s killed after writing more than %d bytes of log output",
getName(), settings.maxLogSize));
} }
for (auto c : data) 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 type = (*json)["type"];
const auto fields = (*json)["fields"]; const auto fields = (*json)["fields"];
if (type == resBuildLogLine) { if (type == resBuildLogLine) {
(*logSink)((fields.size() > 0 ? fields[0].get<std::string>() : "") + "\n"); const std::string logLine =
(fields.size() > 0 ? fields[0].get<std::string>() : "") + "\n";
logSize += logLine.size();
if (settings.maxLogSize && logSize > settings.maxLogSize) {
return tooMuchLogs();
}
(*logSink)(logLine);
} else if (type == resSetPhase && ! fields.is_null()) { } else if (type == resSetPhase && ! fields.is_null()) {
const auto phase = fields[0]; const auto phase = fields[0];
if (! phase.is_null()) { if (! phase.is_null()) {