Skip to content

Commit aac0ed7

Browse files
committed
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 6965ac5 commit aac0ed7

File tree

9 files changed

+35
-40
lines changed

9 files changed

+35
-40
lines changed

src/libstore/build/derivation-goal.cc

Lines changed: 8 additions & 18 deletions
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);
@@ -769,10 +753,11 @@ Goal::Co DerivationGoal::tryToBuild()
769753
currentHookLine,
770754
logTail
771755
);
756+
bool timedOut = false;
772757
co_await childStarted(
773758
{ hook->fromHook.readSide.get()
774759
, hook->builderOut.readSide.get()
775-
}, false, false, std::move(handler));
760+
}, false, false, std::move(handler), timedOut);
776761
trace("calling childStarted hook end");
777762

778763
if (
@@ -782,7 +767,12 @@ Goal::Co DerivationGoal::tryToBuild()
782767
act->result(resBuildLogLine, currentLogLine);
783768
}
784769

785-
if (failed) {
770+
if (timedOut) {
771+
#ifndef _WIN32 // TODO enable build hook on Windows
772+
hook.reset();
773+
#endif
774+
co_return done(BuildResult::TimedOut, {}, std::move(ex));
775+
} else if (failed) {
786776
co_return done(
787777
BuildResult::LogLimitExceeded,
788778
{},

src/libstore/build/derivation-goal.hh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ struct DerivationGoal : public Goal
214214
BuildMode buildMode = bmNormal);
215215
virtual ~DerivationGoal();
216216

217-
void timedOut(Error && ex) override;
218-
219217
std::string key() override;
220218

221219
/**
@@ -272,11 +270,6 @@ struct DerivationGoal : public Goal
272270
*/
273271
SingleDrvOutputs assertPathValidity();
274272

275-
/**
276-
* Forcibly kill the child process, if any.
277-
*/
278-
virtual void killChild();
279-
280273
Co repairClosure();
281274

282275
void started();

src/libstore/build/drv-output-substitution-goal.cc

Lines changed: 3 additions & 1 deletion
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.

src/libstore/build/drv-output-substitution-goal.hh

Lines changed: 0 additions & 2 deletions
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 {

src/libstore/build/goal.cc

Lines changed: 9 additions & 1 deletion
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
}

src/libstore/build/goal.hh

Lines changed: 5 additions & 2 deletions
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

src/libstore/build/substitution-goal.cc

Lines changed: 3 additions & 1 deletion
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

src/libstore/build/substitution-goal.hh

Lines changed: 0 additions & 2 deletions
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.

src/libstore/unix/build/local-derivation-goal.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ struct LocalDerivationGoal : public DerivationGoal
326326
*
327327
* Called by destructor, can't be overridden
328328
*/
329-
void killChild() override final;
329+
void killChild();
330330

331331
/**
332332
* Kill any processes running under the build user UID or in the
@@ -449,8 +449,6 @@ void LocalDerivationGoal::killChild()
449449

450450
pid.wait();
451451
}
452-
453-
DerivationGoal::killChild();
454452
}
455453

456454

@@ -820,7 +818,6 @@ static std::function<bool(Descriptor, std::string_view)> build_handler(
820818
std::string & currentLogLine,
821819
size_t & currentLogLinePos,
822820
std::list<std::string> & logTail
823-
824821
) {
825822
return [&](Descriptor fd, std::string_view data) {
826823
// local & `ssh://`-builds are dealt with here.
@@ -1517,7 +1514,8 @@ Goal::Co LocalDerivationGoal::startBuilder(std::list<std::string> & logTail)
15171514
logTail
15181515
);
15191516

1520-
co_await childStarted({builderOut.get()}, true, true, std::move(handler));
1517+
bool timedOut = false;
1518+
co_await childStarted({builderOut.get()}, true, true, std::move(handler), timedOut);
15211519

15221520
trace("calling childStarted build end");
15231521

@@ -1528,7 +1526,10 @@ Goal::Co LocalDerivationGoal::startBuilder(std::list<std::string> & logTail)
15281526
act->result(resBuildLogLine, currentLogLine);
15291527
}
15301528

1531-
if (failed) {
1529+
if (timedOut) {
1530+
killChild();
1531+
co_return done(BuildResult::TimedOut, {}, std::move(ex));
1532+
} if (failed) {
15321533
killChild();
15331534
co_return done(
15341535
BuildResult::LogLimitExceeded,

0 commit comments

Comments
 (0)