Skip to content

Commit 9a08c42

Browse files
committed
fix(gax): adjust RetryAlgorithm logic for timeout v. exception
1 parent e5e5f14 commit 9a08c42

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetryAlgorithm.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,15 @@ public boolean shouldRetry(
232232
ResponseT previousResponse,
233233
TimedAttemptSettings nextAttemptSettings)
234234
throws CancellationException {
235-
return shouldRetryBasedOnResult(context, previousThrowable, previousResponse)
236-
&& shouldRetryBasedOnTiming(context, nextAttemptSettings);
235+
boolean retryBasedOnResult = shouldRetryBasedOnResult(context, previousThrowable, previousResponse);
236+
237+
// Short-circuit when operation has succeeded to avoid erroneously throwing CancellationException below
238+
if (!retryBasedOnResult && previousThrowable == null) {
239+
return false;
240+
}
241+
242+
boolean retryBasedOnTiming = shouldRetryBasedOnTiming(context, nextAttemptSettings); // throws CancellationException
243+
return retryBasedOnResult && retryBasedOnTiming;
237244
}
238245

239246
boolean shouldRetryBasedOnResult(

0 commit comments

Comments
 (0)