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

fix: retain user RPC timeout if set via withTimeout #1324

Merged
merged 2 commits into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java
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 will limit the duration of a server streaming RPC as
noahdietz marked this conversation as resolved.
Show resolved Hide resolved
* well.
*
* <p>If a method has default {@link com.google.api.gax.retrying.RetrySettings}, the max attempts
* and/or total timeout will still be respected when scheduling each RPC attempt.
noahdietz marked this conversation as resolved.
Show resolved Hide resolved
*/
ApiCallContext withTimeout(@Nullable Duration timeout);

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

try {
// Only attempt to set the RPC timeout if the caller did not provide their own.
noahdietz marked this conversation as resolved.
Show resolved Hide resolved
Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout();
if (!rpcTimeout.isZero()) {
if (!rpcTimeout.isZero() && callContext.getTimeout() == null) {
callContext = callContext.withTimeout(rpcTimeout);
}

Expand Down
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