diff options
author | 2017-08-30 14:37:21 +0200 | |
---|---|---|
committer | 2017-08-30 18:24:19 +0200 | |
commit | 4763abc3764042323efc30844b5b16a8e20fca02 (patch) | |
tree | 78e0d55fa28091cd503678668df3693532f0167e /src/main/java/com/google/devtools | |
parent | aa0093be3800911f6d0f1ff4564d9eebd24fbeae (diff) |
remote: support timeouts
PiperOrigin-RevId: 166981977
Diffstat (limited to 'src/main/java/com/google/devtools')
3 files changed, 41 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java index 06aabda492..3dabf0a677 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java @@ -73,8 +73,7 @@ class GrpcRemoteExecutor { if (e.getStatus().getCode() == Code.DEADLINE_EXCEEDED) { // This was caused by the command itself exceeding the timeout, // therefore it is not retriable. - // TODO(olaola): this should propagate a timeout SpawnResult instead of raising. - throw new IOException("Remote execution time out"); + throw new TimeoutException(); } throw e; } diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java index 26fba9d25c..69b751cbda 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java @@ -45,6 +45,8 @@ import com.google.devtools.remoteexecution.v1test.ExecuteResponse; import com.google.devtools.remoteexecution.v1test.Platform; import io.grpc.Status.Code; import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.ArrayList; import java.util.Collection; @@ -207,9 +209,25 @@ class RemoteSpawnRunner implements SpawnRunner { if (options.remoteLocalFallback) { return execLocally(spawn, policy, inputMap, uploadLocalResults, remoteCache, actionKey); } + if (cause instanceof TimeoutException) { + return handleTimeout(policy.getFileOutErr()); + } throw new EnvironmentalExecException(errorMessage(cause), cause, true); } + private SpawnResult handleTimeout(FileOutErr outErr) throws IOException { + // TODO(buchgr): Once the remote execution protocol allows it, also provide stdout/stderr + // from the action that timed out. + try (OutputStream out = outErr.getOutputStream()) { + // This is a hack to ensure that the test.log file gets created, as else the action + // will complain that one of its outputs has not been created. + String msg = "Log output for timeouts is not yet supported in remote execution."; + out.write(msg.getBytes(StandardCharsets.UTF_8)); + out.flush(); + } + return new SpawnResult.Builder().setStatus(Status.TIMEOUT).build(); + } + private String errorMessage(IOException e) { String message = ""; if (e instanceof RetryException diff --git a/src/main/java/com/google/devtools/build/lib/remote/TimeoutException.java b/src/main/java/com/google/devtools/build/lib/remote/TimeoutException.java new file mode 100644 index 0000000000..f1ba33a8dc --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/remote/TimeoutException.java @@ -0,0 +1,22 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.remote; + +import java.io.IOException; + +/** + * Exception to signal that a remote execution has timed out. + */ +class TimeoutException extends IOException { +} |