Skip to content

Commit 039461c

Browse files
larsrc-googlecopybara-github
authored andcommitted
Adding debugging information for case when two branches apparently cancel each other.
RELNOTES: None. PiperOrigin-RevId: 352596000
1 parent fbbc4f6 commit 039461c

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/main/java/com/google/devtools/build/lib/dynamic/DynamicSpawnStrategy.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,43 @@ private static ImmutableList<SpawnResult> waitBranch(Future<ImmutableList<SpawnR
230230
* <p>This guarantees that the two branches are stopped both on successful termination and on an
231231
* exception.
232232
*
233-
* @param branch1 the future running one side of the spawn (e.g. local). This future must cancel
234-
* {@code branch2} at some point during its successful execution to guarantee termination. If
235-
* we encounter an execution error, or if we are interrupted, then we handle such cancellation
236-
* here.
237-
* @param branch2 the future running the other side of the spawn (e.g. remote). Same restrictions
238-
* apply as in {@code branch1}, but in the symmetric direction.
233+
* @param localBranch the future running the local side of the spawn. This future must cancel
234+
* {@code remoteBranch} at some point during its successful execution to guarantee
235+
* termination. If we encounter an execution error, or if we are interrupted, then we handle
236+
* such cancellation here.
237+
* @param remoteBranch the future running the remote side of the spawn. Same restrictions apply as
238+
* in {@code localBranch}, but in the symmetric direction.
239239
* @return the result of the branch that terminates first
240240
* @throws ExecException the execution error of the spawn that terminated first
241241
* @throws InterruptedException if we get interrupted while waiting for completion
242242
*/
243243
private static ImmutableList<SpawnResult> waitBranches(
244-
Future<ImmutableList<SpawnResult>> branch1, Future<ImmutableList<SpawnResult>> branch2)
244+
Future<ImmutableList<SpawnResult>> localBranch,
245+
Future<ImmutableList<SpawnResult>> remoteBranch)
245246
throws ExecException, InterruptedException {
246-
ImmutableList<SpawnResult> result1;
247+
ImmutableList<SpawnResult> localResult;
247248
try {
248-
result1 = waitBranch(branch1);
249+
localResult = waitBranch(localBranch);
249250
} catch (ExecException | InterruptedException | RuntimeException e) {
250-
branch2.cancel(true);
251+
remoteBranch.cancel(true);
251252
throw e;
252253
}
253254

254-
ImmutableList<SpawnResult> result2 = waitBranch(branch2);
255+
ImmutableList<SpawnResult> remoteResult = waitBranch(remoteBranch);
255256

256-
if (result2 != null && result1 != null) {
257+
if (remoteResult != null && localResult != null) {
257258
throw new AssertionError("One branch did not cancel the other one");
258-
} else if (result2 != null) {
259-
return result2;
260-
} else if (result1 != null) {
261-
return result1;
259+
} else if (remoteResult != null) {
260+
return remoteResult;
261+
} else if (localResult != null) {
262+
return localResult;
262263
} else {
263-
throw new AssertionError("No branch completed, which might mean they cancelled each other");
264+
throw new AssertionError(
265+
"Neither branch completed. Local was "
266+
+ (localBranch.isCancelled() ? "" : "not ")
267+
+ "cancelled and remote was "
268+
+ (remoteBranch.isCancelled() ? "" : "not ")
269+
+ "cancelled");
264270
}
265271
}
266272

0 commit comments

Comments
 (0)