Skip to content
Permalink
Browse files
fix: retain user RPC timeout if set via withTimeout (#1324)
  • Loading branch information
noahdietz committed Mar 10, 2021
1 parent 27d92c6 commit 3fe1db913b134e4fddee4c769ee4497847d8e01f
@@ -63,9 +63,13 @@ public interface ApiCallContext extends RetryingContext {
* Returns a new ApiCallContext with the given timeout set.
*
* <p>This sets the maximum amount of time a single unary RPC attempt can take. If retries are
* enabled, then this can take much longer. Unlike a deadline, timeouts are relative durations
* that are measure from the beginning of each RPC attempt. Please note that this will limit the
* duration of a server streaming RPC as well.
* enabled, then this can take much longer, as each RPC attempt will have the same constant
* timeout. Unlike a deadline, timeouts are relative durations that are measure from the beginning
* of each RPC attempt. Please note that this limits the duration of a server streaming RPC as
* well.
*
* <p>If a method has default {@link com.google.api.gax.retrying.RetrySettings}, the max attempts
* and/or total timeout is still respected when scheduling each RPC attempt.
*/
ApiCallContext withTimeout(@Nullable Duration timeout);

@@ -69,8 +69,9 @@ public ResponseT call() {
ApiCallContext callContext = originalCallContext;

try {
// Set the RPC timeout if the caller did not provide their own.
Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout();
if (!rpcTimeout.isZero()) {
if (!rpcTimeout.isZero() && callContext.getTimeout() == null) {
callContext = callContext.withTimeout(rpcTimeout);
}

@@ -108,6 +108,9 @@ public void testRpcTimeoutIsNotErased() {
Duration callerTimeout = Duration.ofMillis(10);
ApiCallContext callerCallContext = FakeCallContext.createDefault().withTimeout(callerTimeout);

Duration timeout = Duration.ofMillis(5);
currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build();

AttemptCallable<String, String> callable =
new AttemptCallable<>(mockInnerCallable, "fake-request", callerCallContext);
callable.setExternalFuture(mockExternalFuture);

0 comments on commit 3fe1db9

Please sign in to comment.