Add an import label to visitedNested only after we check for a cached value. Otherwise we may add the label to the set of visited items but not remove it.
@@ -145,12 +145,6 @@ public class SkylarkImportLookupFunction implements SkyFunction {
SkylarkImportLookupKey key = (SkylarkImportLookupKey) skyKey.argument();
Label importLabel = key.importLabel;
- if (!visitedNested.add(importLabel)) {
- ImmutableList<Label> cycle =
- CycleUtils.splitIntoPathAndChain(Predicates.equalTo(importLabel), visitedNested).second;
- throw new SkylarkImportFailedException("Starlark import cycle: " + cycle);
- }
-
// Note that we can't block other threads on the computation of this value due to a potential
// deadlock on a cycle. Although we are repeating some work, it is possible we have an import
// cycle where one thread starts at one side of the cycle and the other thread starts at the
@@ -162,6 +156,12 @@ public class SkylarkImportLookupFunction implements SkyFunction {
return cachedSkylarkImportLookupValueAndDeps;
}
+ if (!visitedNested.add(importLabel)) {
+ ImmutableList<Label> cycle =
+ CycleUtils.splitIntoPathAndChain(Predicates.equalTo(importLabel), visitedNested).second;
+ throw new SkylarkImportFailedException("Starlark import cycle: " + cycle);
+ }
+
CachedSkylarkImportLookupValueAndDeps.Builder inlineCachedValueBuilder =
CachedSkylarkImportLookupValueAndDeps.newBuilder();
Preconditions.checkState(
