Skip to content

Commit

Permalink
Print remote execution message when the action times out
Browse files Browse the repository at this point in the history
Closes bazelbuild#15710.

PiperOrigin-RevId: 456227285
Change-Id: I7d938bde6482151d96cb7cfe65242e659a6fb4a2
  • Loading branch information
exoson authored and aranguyen committed Jun 27, 2022
1 parent 4333a23 commit eb85881
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import com.google.devtools.build.lib.remote.common.BulkTransferException;
import com.google.devtools.build.lib.remote.common.OperationObserver;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.remote.options.RemoteOptions.ExecutionMessagePrintMode;
import com.google.devtools.build.lib.remote.util.Utils;
import com.google.devtools.build.lib.remote.util.Utils.InMemoryOutput;
import com.google.devtools.build.lib.sandbox.SandboxHelpers;
Expand Down Expand Up @@ -273,21 +272,7 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
// It's already late at this stage, but we should at least report once.
reporter.reportExecutingIfNot();

FileOutErr outErr = context.getFileOutErr();
String message = result.getMessage();
boolean printMessage =
((!result.success()
&& remoteOptions.remotePrintExecutionMessages
== ExecutionMessagePrintMode.FAILURE)
|| (result.success()
&& remoteOptions.remotePrintExecutionMessages
== ExecutionMessagePrintMode.SUCCESS)
|| remoteOptions.remotePrintExecutionMessages
== ExecutionMessagePrintMode.ALL)
&& !message.isEmpty();
if (printMessage) {
outErr.printErr(message + "\n");
}
maybePrintExecutionMessages(context, result.getMessage(), result.success());

profileAccounting(result.getExecutionMetadata());
spawnMetricsAccounting(spawnMetrics, result.getExecutionMetadata());
Expand Down Expand Up @@ -458,6 +443,17 @@ public boolean handlesCaching() {
return true;
}

private void maybePrintExecutionMessages(
SpawnExecutionContext context, String message, boolean success) {
FileOutErr outErr = context.getFileOutErr();
boolean printMessage =
remoteOptions.remotePrintExecutionMessages.shouldPrintMessages(success)
&& !message.isEmpty();
if (printMessage) {
outErr.printErr(message + "\n");
}
}

private void maybeWriteParamFilesLocally(Spawn spawn) throws IOException {
if (!executionOptions.shouldMaterializeParamFiles()) {
return;
Expand Down Expand Up @@ -514,10 +510,11 @@ private SpawnResult execLocallyAndUploadOrFail(
if (remoteOptions.remoteLocalFallback && !RemoteRetrierUtils.causedByExecTimeout(cause)) {
return execLocallyAndUpload(action, spawn, context, uploadLocalResults);
}
return handleError(action, cause);
return handleError(action, cause, context);
}

private SpawnResult handleError(RemoteAction action, IOException exception)
private SpawnResult handleError(
RemoteAction action, IOException exception, SpawnExecutionContext context)
throws ExecException, InterruptedException, IOException {
boolean remoteCacheFailed =
BulkTransferException.isOnlyCausedByCacheNotFoundException(exception);
Expand All @@ -536,6 +533,7 @@ private SpawnResult handleError(RemoteAction action, IOException exception)
}
}
if (e.isExecutionTimeout()) {
maybePrintExecutionMessages(context, e.getResponse().getMessage(), /* success = */ false);
return new SpawnResult.Builder()
.setRunnerName(getName())
.setStatus(Status.TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,5 +669,11 @@ public Converter() {
super(ExecutionMessagePrintMode.class, "execution message print mode");
}
}

public boolean shouldPrintMessages(boolean success) {
return ((!success && this == ExecutionMessagePrintMode.FAILURE)
|| (success && this == ExecutionMessagePrintMode.SUCCESS)
|| this == ExecutionMessagePrintMode.ALL);
}
}
}

0 comments on commit eb85881

Please sign in to comment.