Skip to content

Commit 224d642

Browse files
yuyue730copybara-github
authored andcommitted
Disable pooled SkyKeyInterner for PackageLoader
Pooled `SkyKeyInterner` assumes that there is only one pool existing in the blaze program, so setting the pool to some container or `null` happens sequentially without synchronization concern. However, this assumption is broken if multiple `PackageLoader` instances are being used with concurrent Skyframe evaluations for other programs than blaze. It is possible that one `PackageLoader` tries to access some SkyKey in the globalPool, but the pool has already been reset by the other `PackageLoader`. In order to avoid this, we disable pooled `SkyKeyInterner` for `PackageLoader` and `SkyKey`s will revert to use the naive weak interner. PiperOrigin-RevId: 531318564 Change-Id: Ie2c7793c3fdc1ad3b6677c13f0d8c00ca8f4125e
1 parent 5bbd8c7 commit 224d642

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java

+5-18
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ public Diff getDiff(WalkableGraph fromGraph, Version fromVersion, Version toVers
140140
private final int nonSkyframeGlobbingThreads;
141141
@VisibleForTesting final ForkJoinPool forkJoinPoolForNonSkyframeGlobbing;
142142
private final int skyframeThreads;
143-
private final boolean usePooledInterning;
144143

145144
/** Abstract base class of a builder for {@link PackageLoader} instances. */
146145
public abstract static class Builder {
@@ -157,7 +156,6 @@ public abstract static class Builder {
157156
List<PrecomputedValue.Injected> extraPrecomputedValues = new ArrayList<>();
158157
int nonSkyframeGlobbingThreads = 1;
159158
int skyframeThreads = 1;
160-
boolean usePooledInterning = true;
161159

162160
protected Builder(
163161
Root workspaceDir,
@@ -243,12 +241,6 @@ public Builder setExternalFileAction(ExternalFileAction externalFileAction) {
243241
return this;
244242
}
245243

246-
@CanIgnoreReturnValue
247-
public Builder disablePooledSkyKeyInterning() {
248-
this.usePooledInterning = false;
249-
return this;
250-
}
251-
252244
/** Throws {@link IllegalArgumentException} if builder args are incomplete/inconsistent. */
253245
protected void validate() {
254246
if (starlarkSemantics == null) {
@@ -280,7 +272,6 @@ public final PackageLoader build() {
280272
NamedForkJoinPool.newNamedPool(
281273
"package-loader-globbing-pool", builder.nonSkyframeGlobbingThreads);
282274
this.skyframeThreads = builder.skyframeThreads;
283-
this.usePooledInterning = builder.usePooledInterning;
284275
this.directories = builder.directories;
285276
this.hashFunction = builder.workspaceDir.getFileSystem().getDigestFunction().getHashFunction();
286277

@@ -362,14 +353,8 @@ private Result loadPackagesInternal(
362353
StoredEventHandler storedEventHandler)
363354
throws InterruptedException {
364355
MemoizingEvaluator evaluator = makeFreshEvaluator();
365-
EvaluationResult<PackageValue> evalResult;
366-
try {
367-
evalResult = evaluator.evaluate(pkgKeys, evaluationContext);
368-
} finally {
369-
if (usePooledInterning) {
370-
evaluator.cleanupInterningPools();
371-
}
372-
}
356+
EvaluationResult<PackageValue> evalResult = evaluator.evaluate(pkgKeys, evaluationContext);
357+
373358
ImmutableMap.Builder<PackageIdentifier, PackageLoader.PackageOrException> result =
374359
ImmutableMap.builder();
375360
for (SkyKey key : pkgKeys) {
@@ -417,7 +402,9 @@ private MemoizingEvaluator makeFreshEvaluator() {
417402
EventFilter.FULL_STORAGE,
418403
new EmittedEventState(),
419404
/* keepEdges= */ false,
420-
usePooledInterning);
405+
// Using pooled interner is unsound if there are multiple MemoizingEvaluators evaluating
406+
// concurrently.
407+
/* usePooledInterning= */ false);
421408
}
422409

423410
protected abstract CrossRepositoryLabelViolationStrategy

0 commit comments

Comments
 (0)