libstore: move respect-timeoutiness to goal method

this is useless to do on the face of it, but it'll make it easier to
convert the entire output handling to use async io and promises soon

Change-Id: I2d1eb62c4bbf8f57bd558b9599c08710a389b1a8
This commit is contained in:
eldritch horrors 2024-08-12 15:51:14 +02:00
parent 3d14567d0b
commit fb8eb539fc
8 changed files with 24 additions and 15 deletions

View file

@ -1213,7 +1213,7 @@ HookReply DerivationGoal::tryBuildHook(bool inBuildSlot)
fds.insert(hook->fromHook.readSide.get()); fds.insert(hook->fromHook.readSide.get());
fds.insert(hook->builderOut.readSide.get()); fds.insert(hook->builderOut.readSide.get());
builderOutFD = &hook->builderOut.readSide; builderOutFD = &hook->builderOut.readSide;
worker.childStarted(shared_from_this(), fds, false, false); worker.childStarted(shared_from_this(), fds, false);
return rpAccept; return rpAccept;
} }

View file

@ -75,7 +75,7 @@ Goal::WorkResult DrvOutputSubstitutionGoal::tryNext(bool inBuildSlot)
return sub->queryRealisation(id); return sub->queryRealisation(id);
}); });
worker.childStarted(shared_from_this(), {downloadState->outPipe.readSide.get()}, true, false); worker.childStarted(shared_from_this(), {downloadState->outPipe.readSide.get()}, true);
state = &DrvOutputSubstitutionGoal::realisationFetched; state = &DrvOutputSubstitutionGoal::realisationFetched;
return StillAlive{}; return StillAlive{};

View file

@ -160,6 +160,11 @@ public:
{ {
} }
virtual bool respectsTimeouts()
{
return false;
}
void trace(std::string_view s); void trace(std::string_view s);
std::string getName() const std::string getName() const

View file

@ -726,7 +726,7 @@ void LocalDerivationGoal::startBuilder()
/* parent */ /* parent */
pid.setSeparatePG(true); pid.setSeparatePG(true);
worker.childStarted(shared_from_this(), {builderOutPTY.get()}, true, true); worker.childStarted(shared_from_this(), {builderOutPTY.get()}, true);
/* Check if setting up the build environment failed. */ /* Check if setting up the build environment failed. */
std::vector<std::string> msgs; std::vector<std::string> msgs;

View file

@ -357,6 +357,10 @@ protected:
return false; return false;
} }
virtual bool respectsTimeouts() override
{
return true;
}
}; };
} }

View file

@ -221,7 +221,7 @@ Goal::WorkResult PathSubstitutionGoal::tryToRun(bool inBuildSlot)
} }
}); });
worker.childStarted(shared_from_this(), {outPipe.readSide.get()}, true, false); worker.childStarted(shared_from_this(), {outPipe.readSide.get()}, true);
state = &PathSubstitutionGoal::finished; state = &PathSubstitutionGoal::finished;
return StillAlive{}; return StillAlive{};

View file

@ -233,7 +233,7 @@ void Worker::wakeUp(GoalPtr goal)
void Worker::childStarted(GoalPtr goal, const std::set<int> & fds, void Worker::childStarted(GoalPtr goal, const std::set<int> & fds,
bool inBuildSlot, bool respectTimeouts) bool inBuildSlot)
{ {
Child child; Child child;
child.goal = goal; child.goal = goal;
@ -241,7 +241,6 @@ void Worker::childStarted(GoalPtr goal, const std::set<int> & fds,
child.fds = fds; child.fds = fds;
child.timeStarted = child.lastOutput = steady_time_point::clock::now(); child.timeStarted = child.lastOutput = steady_time_point::clock::now();
child.inBuildSlot = inBuildSlot; child.inBuildSlot = inBuildSlot;
child.respectTimeouts = respectTimeouts;
children.emplace_back(child); children.emplace_back(child);
if (inBuildSlot) { if (inBuildSlot) {
switch (goal->jobCategory()) { switch (goal->jobCategory()) {
@ -427,12 +426,14 @@ void Worker::waitForInput()
// Periodicallty wake up to see if we need to run the garbage collector. // Periodicallty wake up to see if we need to run the garbage collector.
nearest = before + std::chrono::seconds(10); nearest = before + std::chrono::seconds(10);
for (auto & i : children) { for (auto & i : children) {
if (!i.respectTimeouts) continue; if (auto goal = i.goal.lock()) {
if (!goal->respectsTimeouts()) continue;
if (0 != settings.maxSilentTime) if (0 != settings.maxSilentTime)
nearest = std::min(nearest, i.lastOutput + std::chrono::seconds(settings.maxSilentTime)); nearest = std::min(nearest, i.lastOutput + std::chrono::seconds(settings.maxSilentTime));
if (0 != settings.buildTimeout) if (0 != settings.buildTimeout)
nearest = std::min(nearest, i.timeStarted + std::chrono::seconds(settings.buildTimeout)); nearest = std::min(nearest, i.timeStarted + std::chrono::seconds(settings.buildTimeout));
} }
}
if (nearest != steady_time_point::max()) { if (nearest != steady_time_point::max()) {
timeout = std::max(1L, (long) std::chrono::duration_cast<std::chrono::seconds>(nearest - before).count()); timeout = std::max(1L, (long) std::chrono::duration_cast<std::chrono::seconds>(nearest - before).count());
useTimeout = true; useTimeout = true;
@ -484,7 +485,7 @@ void Worker::waitForInput()
if (!goal->exitCode.has_value() && if (!goal->exitCode.has_value() &&
0 != settings.maxSilentTime && 0 != settings.maxSilentTime &&
j->respectTimeouts && goal->respectsTimeouts() &&
after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime))
{ {
handleWorkResult( handleWorkResult(
@ -500,7 +501,7 @@ void Worker::waitForInput()
else if (!goal->exitCode.has_value() && else if (!goal->exitCode.has_value() &&
0 != settings.buildTimeout && 0 != settings.buildTimeout &&
j->respectTimeouts && goal->respectsTimeouts() &&
after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout)) after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout))
{ {
handleWorkResult( handleWorkResult(

View file

@ -29,7 +29,6 @@ struct Child
WeakGoalPtr goal; WeakGoalPtr goal;
Goal * goal2; // ugly hackery Goal * goal2; // ugly hackery
std::set<int> fds; std::set<int> fds;
bool respectTimeouts;
bool inBuildSlot; bool inBuildSlot;
/** /**
* Time we last got output on stdout/stderr * Time we last got output on stdout/stderr
@ -234,7 +233,7 @@ public:
* the process counts towards the jobs limit. * the process counts towards the jobs limit.
*/ */
void childStarted(GoalPtr goal, const std::set<int> & fds, void childStarted(GoalPtr goal, const std::set<int> & fds,
bool inBuildSlot, bool respectTimeouts); bool inBuildSlot);
/** /**
* Unregisters a running child process. * Unregisters a running child process.