Skip to content

Commit

Permalink
Specify an appropriate FailureDetail when crashing due to an interr…
Browse files Browse the repository at this point in the history
…upt during `NestedSet` deserialization.

In the absence of a specified `FailureDetail`, the generic `CRASH_UNKNOWN` is used.

PiperOrigin-RevId: 364663618
  • Loading branch information
justinhorvitz authored and copybara-github committed Mar 23, 2021
1 parent 9a56b80 commit db9467f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization:constants",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
"//src/main/java/com/google/devtools/build/lib/util:exit_code",
"//src/main/java/net/starlark/java/annot",
"//src/main/java/net/starlark/java/eval",
"//src/main/protobuf:failure_details_java_proto",
"//third_party:auto_value",
"//third_party:flogger",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetStore.MissingNestedSetException;
import com.google.devtools.build.lib.concurrent.MoreFutures;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.Interrupted;
import com.google.devtools.build.lib.server.FailureDetails.Interrupted.Code;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.util.DetailedExitCode;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.protobuf.ByteString;
import java.time.Duration;
Expand Down Expand Up @@ -286,21 +290,25 @@ enum InterruptStrategy {
PROPAGATE
}

/** Implementation of {@link #getChildren} that will catch an InterruptedException and crash. */
/**
* Implementation of {@link #getChildren} that crashes with the appropriate failure detail if it
* encounters {@link InterruptedException}.
*/
private Object getChildrenUninterruptibly() {
if (children instanceof ListenableFuture) {
try {
return MoreFutures.waitForFutureAndGet((ListenableFuture<Object[]>) children);
} catch (InterruptedException e) {
System.err.println(
"An interrupted exception occurred during nested set deserialization, "
+ "exiting abruptly.");
BugReport.handleCrash(Crash.from(e, ExitCode.INTERRUPTED), CrashContext.halt());
throw new IllegalStateException("Should have halted", e);
}
} else {
if (!(children instanceof ListenableFuture)) {
return children;
}
try {
return MoreFutures.waitForFutureAndGet((ListenableFuture<Object[]>) children);
} catch (InterruptedException e) {
FailureDetail failureDetail =
FailureDetail.newBuilder()
.setMessage("Interrupted during NestedSet deserialization")
.setInterrupted(Interrupted.newBuilder().setCode(Code.INTERRUPTED))
.build();
BugReport.handleCrash(Crash.from(e, DetailedExitCode.of(failureDetail)), CrashContext.halt());
throw new IllegalStateException("Should have halted", e);
}
}

/**
Expand Down

0 comments on commit db9467f

Please sign in to comment.