1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-22 08:51:08 +01:00

Make worker timeouts a bit more strongly typed

This tidies things up in general, but also prepares the way for the next
commit in particular.
This commit is contained in:
John Ericson 2025-12-13 23:18:01 -05:00
parent b398c14045
commit 906334686c
10 changed files with 24 additions and 12 deletions

View file

@ -71,12 +71,12 @@ void DerivationBuildingGoal::killChild()
#endif
}
void DerivationBuildingGoal::timedOut(Error && ex)
void DerivationBuildingGoal::timedOut(TimedOut && ex)
{
killChild();
// We're not inside a coroutine, hence we can't use co_return here.
// Thus we ignore the return value.
[[maybe_unused]] Done _ = doneFailure({BuildResult::Failure::TimedOut, std::move(ex)});
[[maybe_unused]] Done _ = doneFailure(std::move(ex));
}
std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv)

View file

@ -4,6 +4,12 @@
namespace nix {
TimedOut::TimedOut(time_t maxDuration)
: BuildError(BuildResult::Failure::TimedOut, "timed out after %1% seconds", maxDuration)
, maxDuration(maxDuration)
{
}
using Co = nix::Goal::Co;
using promise_type = nix::Goal::promise_type;
using handle_type = nix::Goal::handle_type;

View file

@ -479,14 +479,13 @@ void Worker::waitForInput()
if (goal->exitCode == Goal::ecBusy && 0 != settings.maxSilentTime && j->respectTimeouts
&& after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) {
goal->timedOut(
Error("%1% timed out after %2% seconds of silence", goal->getName(), settings.maxSilentTime));
goal->timedOut(TimedOut(settings.maxSilentTime));
}
else if (
goal->exitCode == Goal::ecBusy && 0 != settings.buildTimeout && j->respectTimeouts
&& after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout)) {
goal->timedOut(Error("%1% timed out after %2% seconds", goal->getName(), settings.buildTimeout));
goal->timedOut(TimedOut(settings.buildTimeout));
}
}

View file

@ -100,7 +100,7 @@ private:
std::map<ActivityId, Activity> builderActivities;
void timedOut(Error && ex) override;
void timedOut(TimedOut && ex) override;
std::string key() override;

View file

@ -52,7 +52,7 @@ struct DerivationGoal : public Goal
bool storeDerivation);
~DerivationGoal() = default;
void timedOut(Error && ex) override
void timedOut(TimedOut && ex) override
{
unreachable();
};

View file

@ -43,7 +43,7 @@ struct DerivationResolutionGoal : public Goal
*/
std::unique_ptr<std::pair<StorePath, BasicDerivation>> resolvedDrv;
void timedOut(Error && ex) override {}
void timedOut(TimedOut && ex) override {}
private:

View file

@ -109,7 +109,7 @@ struct DerivationTrampolineGoal : public Goal
virtual ~DerivationTrampolineGoal();
void timedOut(Error && ex) override {}
void timedOut(TimedOut && ex) override {}
std::string key() override;

View file

@ -33,7 +33,7 @@ public:
Co init();
void timedOut(Error && ex) override
void timedOut(TimedOut && ex) override
{
unreachable();
};

View file

@ -8,6 +8,13 @@
namespace nix {
struct TimedOut : BuildError
{
time_t maxDuration;
TimedOut(time_t maxDuration);
};
/**
* Forward definition.
*/
@ -454,7 +461,7 @@ public:
* get rid of any running child processes that are being monitored
* by the worker (important!), etc.
*/
virtual void timedOut(Error && ex) = 0;
virtual void timedOut(TimedOut && ex) = 0;
/**
* Used for comparisons. The order matters a bit for scheduling. We

View file

@ -53,7 +53,7 @@ public:
std::optional<ContentAddress> ca = std::nullopt);
~PathSubstitutionGoal();
void timedOut(Error && ex) override
void timedOut(TimedOut && ex) override
{
unreachable();
};