Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
fix: retain user RPC timeout if set via withTimeout (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Mar 10, 2021
1 parent 27d92c6 commit 3fe1db9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3fe1db9

Please sign in to comment.