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 573d3b9666baf6..7916e79a9a649f 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 @@ -32,6 +32,7 @@ import java.util.Iterator; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; /** A remote work executor that uses gRPC for communicating the work, inputs and outputs. */ @@ -57,9 +58,13 @@ public GrpcRemoteExecutor( } private ExecutionBlockingStub execBlockingStub() { - return ExecutionGrpc.newBlockingStub(channel) + ExecutionBlockingStub stub = ExecutionGrpc.newBlockingStub(channel) .withInterceptors(TracingMetadataUtils.attachMetadataFromContextInterceptor()) .withCallCredentials(callCredentials); + if (options.remoteExecuteTimeout != null){ + stub = stub.withDeadlineAfter(options.remoteExecuteTimeout.getSeconds(), TimeUnit.SECONDS); + } + return stub; } private void handleStatus(Status statusProto, @Nullable ExecuteResponse resp) { diff --git a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java index ec4feb60755b35..61ff031cac5793 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java +++ b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java @@ -173,6 +173,19 @@ public final class RemoteOptions extends OptionsBase { + " the unit is omitted, the value is interpreted as seconds.") public Duration remoteTimeout; + @Option( + name = "experimental_remote_execute_timeout", + defaultValue = "null", + documentationCategory = OptionDocumentationCategory.REMOTE, + effectTags = {OptionEffectTag.UNKNOWN}, + converter = RemoteTimeoutConverter.class, + help = + "The maximum amount of time to wait for remote execution's execute response" + + " Following units can be" + + " used: Days (d), hours (h), minutes (m), seconds (s), and milliseconds (ms). If" + + " the unit is omitted, the value is interpreted as seconds.") + public Duration remoteExecuteTimeout; + /** Returns the specified duration. Assumes seconds if unitless. */ public static class RemoteTimeoutConverter implements Converter { private static final Pattern UNITLESS_REGEX = Pattern.compile("^[0-9]+$");