mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Gracefully fallback from failing substituters
This commit is contained in:
parent
587b5f5361
commit
29f9facf76
3 changed files with 29 additions and 12 deletions
|
@ -60,6 +60,10 @@ Goal::Co PathSubstitutionGoal::init()
|
|||
|
||||
for (const auto & sub : subs) {
|
||||
trace("trying next substituter");
|
||||
// If sub is not first, previous one must have failed, so warn
|
||||
if (&sub != &subs.front()) {
|
||||
warn("trying next substituter, '%s'", sub->getUri());
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
|
@ -80,14 +84,21 @@ Goal::Co PathSubstitutionGoal::init()
|
|||
continue;
|
||||
}
|
||||
|
||||
auto path = subPath ? *subPath : storePath;
|
||||
try {
|
||||
// FIXME: make async
|
||||
info = sub->queryPathInfo(subPath ? *subPath : storePath);
|
||||
info = sub->queryPathInfo(path);
|
||||
// Because the path doesn't exist
|
||||
} catch (InvalidPath &) {
|
||||
continue;
|
||||
// Because the substituter has failed recently
|
||||
} catch (SubstituterDisabled & e) {
|
||||
if (settings.tryFallback) continue;
|
||||
else throw e;
|
||||
warn(
|
||||
"Substituter '%s' was disabled when getting info for path '%s'",
|
||||
sub->getUri(),
|
||||
sub->printStorePath(path));
|
||||
continue;
|
||||
// Any other error
|
||||
} catch (Error & e) {
|
||||
if (settings.tryFallback) {
|
||||
logError(e.info());
|
||||
|
|
|
@ -97,12 +97,10 @@ protected:
|
|||
void maybeDisable()
|
||||
{
|
||||
auto state(_state.lock());
|
||||
if (state->enabled && settings.tryFallback) {
|
||||
int t = 60;
|
||||
printError("disabling binary cache '%s' for %s seconds", getUri(), t);
|
||||
state->enabled = false;
|
||||
state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t);
|
||||
}
|
||||
int t = 60;
|
||||
warn("disabling binary cache '%s' for %s seconds", getUri(), t);
|
||||
state->enabled = false;
|
||||
state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t);
|
||||
}
|
||||
|
||||
void checkEnabled()
|
||||
|
|
|
@ -520,7 +520,8 @@ StorePathSet Store::queryDerivationOutputs(const StorePath & path)
|
|||
void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos)
|
||||
{
|
||||
if (!settings.useSubstitutes) return;
|
||||
for (auto & sub : getDefaultSubstituters()) {
|
||||
auto substituters = getDefaultSubstituters();
|
||||
for (auto & sub : substituters) {
|
||||
for (auto & path : paths) {
|
||||
if (infos.count(path.first))
|
||||
// Choose first succeeding substituter.
|
||||
|
@ -557,10 +558,17 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta
|
|||
} catch (InvalidPath &) {
|
||||
} catch (SubstituterDisabled &) {
|
||||
} catch (Error & e) {
|
||||
if (settings.tryFallback)
|
||||
// if last substituter, THEN log error and throw, otherwise warn
|
||||
if (&sub == &substituters.back() && settings.tryFallback) {
|
||||
logError(e.info());
|
||||
else
|
||||
throw;
|
||||
} else {
|
||||
warn(
|
||||
"Unable to download '%s' from subsituter '%s'\n%s",
|
||||
sub->printStorePath(subPath),
|
||||
sub->getUri(),
|
||||
e.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue