Add an option to limit the log output of builders

This is mostly useful for Hydra to deal with builders that get stuck
in an infinite loop writing data to stdout/stderr.
This commit is contained in:
Eelco Dolstra 2013-09-02 11:58:18 +02:00
parent afc6c1bad6
commit efe4289464
4 changed files with 34 additions and 0 deletions

View File

@ -148,6 +148,7 @@ flag, e.g. <literal>--option gc-keep-outputs false</literal>.</para>
</varlistentry> </varlistentry>
<varlistentry xml:id="conf-build-timeout"><term><literal>build-timeout</literal></term> <varlistentry xml:id="conf-build-timeout"><term><literal>build-timeout</literal></term>
<listitem> <listitem>
@ -168,6 +169,20 @@ flag, e.g. <literal>--option gc-keep-outputs false</literal>.</para>
</varlistentry> </varlistentry>
<varlistentry xml:id="conf-build-max-log-size"><term><literal>build-max-log-size</literal></term>
<listitem>
<para>This option defines the maximum number of bytes that a
builder can write to its stdout/stderr. If the builder exceeds
this limit, its killed. A value of <literal>0</literal> (the
default) means that there is no limit.</para>
</listitem>
</varlistentry>
<varlistentry xml:id="conf-build-users-group"><term><literal>build-users-group</literal></term> <varlistentry xml:id="conf-build-users-group"><term><literal>build-users-group</literal></term>
<listitem><para>This options specifies the Unix group containing <listitem><para>This options specifies the Unix group containing

View File

@ -813,6 +813,9 @@ private:
BZFILE * bzLogFile; BZFILE * bzLogFile;
AutoCloseFD fdLogFile; AutoCloseFD fdLogFile;
/* Number of bytes received from the builder's stdout/stderr. */
unsigned long logSize;
/* Pipe for the builder's standard output/error. */ /* Pipe for the builder's standard output/error. */
Pipe builderOut; Pipe builderOut;
@ -2403,6 +2406,8 @@ string drvsLogDir = "drvs";
Path DerivationGoal::openLogFile() Path DerivationGoal::openLogFile()
{ {
logSize = 0;
if (!settings.keepLog) return ""; if (!settings.keepLog) return "";
string baseName = baseNameOf(drvPath); string baseName = baseNameOf(drvPath);
@ -2478,6 +2483,14 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
if ((hook && fd == hook->builderOut.readSide) || if ((hook && fd == hook->builderOut.readSide) ||
(!hook && fd == builderOut.readSide)) (!hook && fd == builderOut.readSide))
{ {
logSize += data.size();
if (settings.maxLogSize && logSize > settings.maxLogSize) {
printMsg(lvlError,
format("%1% killed after writing more than %2% bytes of log output")
% getName() % settings.maxLogSize);
cancel(true); // not really a timeout, but close enough
return;
}
if (verbosity >= settings.buildVerbosity) if (verbosity >= settings.buildVerbosity)
writeToStderr(data); writeToStderr(data);
if (bzLogFile) { if (bzLogFile) {

View File

@ -46,6 +46,7 @@ Settings::Settings()
impersonateLinux26 = false; impersonateLinux26 = false;
keepLog = true; keepLog = true;
compressLog = true; compressLog = true;
maxLogSize = 0;
cacheFailure = false; cacheFailure = false;
pollInterval = 5; pollInterval = 5;
checkRootReachability = false; checkRootReachability = false;
@ -140,6 +141,7 @@ void Settings::update()
get(impersonateLinux26, "build-impersonate-linux-26"); get(impersonateLinux26, "build-impersonate-linux-26");
get(keepLog, "build-keep-log"); get(keepLog, "build-keep-log");
get(compressLog, "build-compress-log"); get(compressLog, "build-compress-log");
get(maxLogSize, "build-max-log-size");
get(cacheFailure, "build-cache-failure"); get(cacheFailure, "build-cache-failure");
get(pollInterval, "build-poll-interval"); get(pollInterval, "build-poll-interval");
get(checkRootReachability, "gc-check-reachability"); get(checkRootReachability, "gc-check-reachability");

View File

@ -153,6 +153,10 @@ struct Settings {
/* Whether to compress logs. */ /* Whether to compress logs. */
bool compressLog; bool compressLog;
/* Maximum number of bytes a builder can write to stdout/stderr
before being killed (0 means no limit). */
unsigned long maxLogSize;
/* Whether to cache build failures. */ /* Whether to cache build failures. */
bool cacheFailure; bool cacheFailure;