Skip to content

Commit aa9ff52

Browse files
[Caching] Make ActionCache update failure non-fatal temporarily
Temporarily make action cache update non-fatal and not failing the job. The action cache update failure can happen due to cache poisoning from non-deterministic compiler output. Assume the errors from the non-determinism is benign and can be ignored till all issues are resolved. rdar://146780363
1 parent 1392926 commit aa9ff52

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lib/Frontend/CASOutputBackends.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,30 @@ Error SwiftCASOutputBackend::Implementation::finalizeCacheKeysFor(
325325
<< CAS.getID(*CacheKey).toString() << "\' => \'"
326326
<< CAS.getID(*Result).toString() << "\'\n";);
327327

328-
if (auto E = Cache.put(CAS.getID(*CacheKey), CAS.getID(*Result)))
329-
return E;
328+
if (auto E = Cache.put(CAS.getID(*CacheKey), CAS.getID(*Result))) {
329+
// If `SWIFT_STRICT_CAS_ERRORS` environment is set, do not attempt to
330+
// recover from error.
331+
if (::getenv("SWIFT_STRICT_CAS_ERRORS"))
332+
return E;
333+
// Failed to update the action cache, this can happen when there is a
334+
// non-deterministic output from compiler. Check that the cache entry is
335+
// not missing, if so, then assume this is a cache poisoning that might
336+
// be benign and the build might continue without problem.
337+
auto Check = Cache.get(CAS.getID(*CacheKey));
338+
if (!Check) {
339+
// A real CAS error, return the original error.
340+
consumeError(Check.takeError());
341+
return E;
342+
}
343+
if (!*Check)
344+
return E;
345+
// Emit an error message to stderr but don't fail the job. Ideally this
346+
// should be sent to a DiagnosticEngine but CASBackend lives longer than
347+
// diagnostic engine and needs to capture all diagnostic outputs before
348+
// sending this request.
349+
llvm::errs() << "error: failed to update cache: " << toString(std::move(E))
350+
<< "\n";
351+
}
330352

331353
return Error::success();
332354
}

0 commit comments

Comments
 (0)