1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Gracefully fallback from failing substituters

This commit is contained in:
Philip Wilk 2025-05-30 20:40:42 +01:00
parent 587b5f5361
commit 29f9facf76
No known key found for this signature in database
3 changed files with 29 additions and 12 deletions

View file

@ -60,6 +60,10 @@ Goal::Co PathSubstitutionGoal::init()
for (const auto & sub : subs) { for (const auto & sub : subs) {
trace("trying next substituter"); 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(); cleanup();
@ -80,14 +84,21 @@ Goal::Co PathSubstitutionGoal::init()
continue; continue;
} }
auto path = subPath ? *subPath : storePath;
try { try {
// FIXME: make async // FIXME: make async
info = sub->queryPathInfo(subPath ? *subPath : storePath); info = sub->queryPathInfo(path);
// Because the path doesn't exist
} catch (InvalidPath &) { } catch (InvalidPath &) {
continue; continue;
// Because the substituter has failed recently
} catch (SubstituterDisabled & e) { } catch (SubstituterDisabled & e) {
if (settings.tryFallback) continue; warn(
else throw e; "Substituter '%s' was disabled when getting info for path '%s'",
sub->getUri(),
sub->printStorePath(path));
continue;
// Any other error
} catch (Error & e) { } catch (Error & e) {
if (settings.tryFallback) { if (settings.tryFallback) {
logError(e.info()); logError(e.info());

View file

@ -97,12 +97,10 @@ protected:
void maybeDisable() void maybeDisable()
{ {
auto state(_state.lock()); auto state(_state.lock());
if (state->enabled && settings.tryFallback) { int t = 60;
int t = 60; warn("disabling binary cache '%s' for %s seconds", getUri(), t);
printError("disabling binary cache '%s' for %s seconds", getUri(), t); state->enabled = false;
state->enabled = false; state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t);
state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t);
}
} }
void checkEnabled() void checkEnabled()

View file

@ -520,7 +520,8 @@ StorePathSet Store::queryDerivationOutputs(const StorePath & path)
void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos) void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos)
{ {
if (!settings.useSubstitutes) return; if (!settings.useSubstitutes) return;
for (auto & sub : getDefaultSubstituters()) { auto substituters = getDefaultSubstituters();
for (auto & sub : substituters) {
for (auto & path : paths) { for (auto & path : paths) {
if (infos.count(path.first)) if (infos.count(path.first))
// Choose first succeeding substituter. // Choose first succeeding substituter.
@ -557,10 +558,17 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta
} catch (InvalidPath &) { } catch (InvalidPath &) {
} catch (SubstituterDisabled &) { } catch (SubstituterDisabled &) {
} catch (Error & e) { } 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()); logError(e.info());
else
throw; throw;
} else {
warn(
"Unable to download '%s' from subsituter '%s'\n%s",
sub->printStorePath(subPath),
sub->getUri(),
e.message());
}
} }
} }
} }