Skip to content

Commit 4041b24

Browse files
L-asEricson2314
authored andcommitted
Remove timeout from Goal
This removes the last additional entry point into Goal's subclasses, such that the CFG in the subclasses is now trivial to see.
1 parent ececce5 commit 4041b24

9 files changed

+35
-40
lines changed

Diff for: src/libstore/build/derivation-goal.cc

+8-18
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,6 @@ std::string DerivationGoal::key()
9696
}
9797

9898

99-
void DerivationGoal::killChild()
100-
{
101-
#ifndef _WIN32 // TODO enable build hook on Windows
102-
hook.reset();
103-
#endif
104-
}
105-
106-
107-
void DerivationGoal::timedOut(Error && ex)
108-
{
109-
killChild();
110-
// We're not inside a coroutine, hence we can't use co_return here.
111-
// Thus we ignore the return value.
112-
[[maybe_unused]] Done _ = done(BuildResult::TimedOut, {}, std::move(ex));
113-
}
114-
11599
void DerivationGoal::addWantedOutputs(const OutputsSpec & outputs)
116100
{
117101
auto newWanted = wantedOutputs.union_(outputs);
@@ -778,11 +762,12 @@ Goal::Co DerivationGoal::tryToBuild()
778762
currentHookLine,
779763
logTail
780764
);
765+
bool timedOut = false;
781766
#ifndef _WIN32 // TODO enable build hook on Windows
782767
co_await childStarted(
783768
{ hook->fromHook.readSide.get()
784769
, hook->builderOut.readSide.get()
785-
}, false, false, std::move(handler));
770+
}, false, false, std::move(handler), timedOut);
786771
trace("calling childStarted hook end");
787772
#endif
788773

@@ -793,7 +778,12 @@ Goal::Co DerivationGoal::tryToBuild()
793778
act->result(resBuildLogLine, currentLogLine);
794779
}
795780

796-
if (failed) {
781+
if (timedOut) {
782+
#ifndef _WIN32 // TODO enable build hook on Windows
783+
hook.reset();
784+
#endif
785+
co_return done(BuildResult::TimedOut, {}, std::move(ex));
786+
} else if (failed) {
797787
co_return done(
798788
BuildResult::LogLimitExceeded,
799789
{},

Diff for: src/libstore/build/derivation-goal.hh

-7
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ struct DerivationGoal : public Goal
209209
BuildMode buildMode = bmNormal);
210210
virtual ~DerivationGoal();
211211

212-
void timedOut(Error && ex) override;
213-
214212
std::string key() override;
215213

216214
/**
@@ -267,11 +265,6 @@ struct DerivationGoal : public Goal
267265
*/
268266
SingleDrvOutputs assertPathValidity();
269267

270-
/**
271-
* Forcibly kill the child process, if any.
272-
*/
273-
virtual void killChild();
274-
275268
Co repairClosure();
276269

277270
void started();

Diff for: src/libstore/build/drv-output-substitution-goal.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ Goal::Co DrvOutputSubstitutionGoal::init()
5858
}
5959
} });
6060

61+
bool timedOut = false;
6162
co_await childStarted({
6263
#ifndef _WIN32
6364
outPipe->readSide.get()
6465
#else
6566
&*outPipe
6667
#endif
67-
}, true, false, [](Descriptor, std::string_view) {return false;});
68+
}, true, false, [](Descriptor, std::string_view) {return false;}, timedOut);
69+
assert(!timedOut);
6870

6971
/*
7072
* The realisation corresponding to the given output id.

Diff for: src/libstore/build/drv-output-substitution-goal.hh

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public:
3636
Co init() override;
3737
Co realisationFetched(Goals waitees, std::shared_ptr<const Realisation> outputInfo, nix::ref<nix::Store> sub);
3838

39-
void timedOut(Error && ex) override { unreachable(); };
40-
4139
std::string key() override;
4240

4341
JobCategory jobCategory() const override {

Diff for: src/libstore/build/goal.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,26 @@ void Goal::handleChildOutput(Descriptor fd, std::string_view data) {
244244
}
245245
}
246246

247+
void Goal::timedOut(Error && ex) {
248+
didTimeOut = true;
249+
worker.wakeUp(shared_from_this());
250+
}
251+
247252
Co Goal::childStarted(
248253
const std::set<MuxablePipePollState::CommChannel> & channels,
249254
bool inBuildSlot,
250255
bool respectTimeouts,
251-
std::function<bool(Descriptor fd, std::string_view data)> handler
256+
std::function<bool(Descriptor fd, std::string_view data)> handler,
257+
bool& timedOut
252258
) {
253259
worker.childStarted(shared_from_this(), channels, inBuildSlot, respectTimeouts);
260+
didTimeOut = false;
254261
assert(handler);
255262
childHandler = std::move(handler);
256263
co_await Suspend{};
257264
trace("done listening to children");
258265
childHandler = {};
266+
timedOut = didTimeOut;
259267
worker.childTerminated(this);
260268
co_return Return{};
261269
}

Diff for: src/libstore/build/goal.hh

+5-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public:
411411
* get rid of any running child processes that are being monitored
412412
* by the worker (important!), etc.
413413
*/
414-
virtual void timedOut(Error && ex) = 0;
414+
void timedOut(Error && ex);
415415

416416
virtual std::string key() = 0;
417417

@@ -424,6 +424,8 @@ public:
424424
private:
425425
std::function<bool(Descriptor, std::string_view)> childHandler;
426426

427+
bool didTimeOut;
428+
427429
protected:
428430
Co await(Goals waitees);
429431

@@ -435,7 +437,8 @@ protected:
435437
const std::set<MuxablePipePollState::CommChannel> & channels,
436438
bool inBuildSlot,
437439
bool respectTimeouts,
438-
std::function<bool(Descriptor, std::string_view)> handler
440+
std::function<bool(Descriptor, std::string_view)> handler,
441+
bool& timedOut
439442
);
440443
};
441444

Diff for: src/libstore/build/substitution-goal.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,15 @@ Goal::Co PathSubstitutionGoal::tryToRun(StorePath subPath, nix::ref<Store> sub,
219219
}
220220
});
221221

222+
bool timedOut = false;
222223
co_await childStarted({
223224
#ifndef _WIN32
224225
outPipe.readSide.get()
225226
#else
226227
&outPipe
227228
#endif
228-
}, true, false, [](Descriptor, std::string_view) {return false;});
229+
}, true, false, [](Descriptor, std::string_view) {return false;}, timedOut);
230+
assert(!timedOut);
229231

230232
trace("substitute finished");
231233

Diff for: src/libstore/build/substitution-goal.hh

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public:
5050
PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
5151
~PathSubstitutionGoal();
5252

53-
void timedOut(Error && ex) override { unreachable(); };
54-
5553
/**
5654
* We prepend "a$" to the key name to ensure substitution goals
5755
* happen before derivation goals.

Diff for: src/libstore/unix/build/local-derivation-goal.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ struct LocalDerivationGoal : DerivationGoal, RestrictionContext
319319
*
320320
* Called by destructor, can't be overridden
321321
*/
322-
void killChild() override final;
322+
void killChild();
323323

324324
/**
325325
* Kill any processes running under the build user UID or in the
@@ -442,8 +442,6 @@ void LocalDerivationGoal::killChild()
442442

443443
pid.wait();
444444
}
445-
446-
DerivationGoal::killChild();
447445
}
448446

449447

@@ -814,7 +812,6 @@ static std::function<bool(Descriptor, std::string_view)> build_handler(
814812
std::string & currentLogLine,
815813
size_t & currentLogLinePos,
816814
std::list<std::string> & logTail
817-
818815
) {
819816
return [&](Descriptor fd, std::string_view data) {
820817
// local & `ssh://`-builds are dealt with here.
@@ -1511,7 +1508,8 @@ Goal::Co LocalDerivationGoal::startBuilder(std::list<std::string> & logTail)
15111508
logTail
15121509
);
15131510

1514-
co_await childStarted({builderOut.get()}, true, true, std::move(handler));
1511+
bool timedOut = false;
1512+
co_await childStarted({builderOut.get()}, true, true, std::move(handler), timedOut);
15151513

15161514
trace("calling childStarted build end");
15171515

@@ -1522,7 +1520,10 @@ Goal::Co LocalDerivationGoal::startBuilder(std::list<std::string> & logTail)
15221520
act->result(resBuildLogLine, currentLogLine);
15231521
}
15241522

1525-
if (failed) {
1523+
if (timedOut) {
1524+
killChild();
1525+
co_return done(BuildResult::TimedOut, {}, std::move(ex));
1526+
} if (failed) {
15261527
killChild();
15271528
co_return done(
15281529
BuildResult::LogLimitExceeded,

0 commit comments

Comments
 (0)