1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-22 17:01: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 #endif
} }
void DerivationBuildingGoal::timedOut(Error && ex) void DerivationBuildingGoal::timedOut(TimedOut && ex)
{ {
killChild(); killChild();
// We're not inside a coroutine, hence we can't use co_return here. // We're not inside a coroutine, hence we can't use co_return here.
// Thus we ignore the return value. // 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) std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv)

View file

@ -4,6 +4,12 @@
namespace nix { 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 Co = nix::Goal::Co;
using promise_type = nix::Goal::promise_type; using promise_type = nix::Goal::promise_type;
using handle_type = nix::Goal::handle_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 if (goal->exitCode == Goal::ecBusy && 0 != settings.maxSilentTime && j->respectTimeouts
&& after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) { && after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) {
goal->timedOut( goal->timedOut(TimedOut(settings.maxSilentTime));
Error("%1% timed out after %2% seconds of silence", goal->getName(), settings.maxSilentTime));
} }
else if ( else if (
goal->exitCode == Goal::ecBusy && 0 != settings.buildTimeout && j->respectTimeouts goal->exitCode == Goal::ecBusy && 0 != settings.buildTimeout && j->respectTimeouts
&& after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout)) { && 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; std::map<ActivityId, Activity> builderActivities;
void timedOut(Error && ex) override; void timedOut(TimedOut && ex) override;
std::string key() override; std::string key() override;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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