From 05548d5ba287af5a8833402108ac55d900889a38 Mon Sep 17 00:00:00 2001 From: Alice <65933803+alicejli@users.noreply.github.com> Date: Wed, 15 Sep 2021 09:23:19 -0700 Subject: [PATCH] fix: editing retry logic (#1100) --- src/gax.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/gax.ts b/src/gax.ts index be20b8e37..b46a30184 100644 --- a/src/gax.ts +++ b/src/gax.ts @@ -211,8 +211,32 @@ export class CallSettings { let longrunning = this.longrunning; let apiName = this.apiName; let retryRequestOptions = this.retryRequestOptions; + // If a method-specific timeout is set in the service config, and the retry codes for that + // method are non-null, then that timeout value will be used to + // override backoff settings. + if ( + retry !== undefined && + retry !== null && + retry.retryCodes !== null && + retry.retryCodes.length > 0 + ) { + retry.backoffSettings.initialRpcTimeoutMillis = timeout; + retry.backoffSettings.maxRpcTimeoutMillis = timeout; + retry.backoffSettings.totalTimeoutMillis = timeout; + } + // If the user provides a timeout to the method, that timeout value will be used + // to override the backoff settings. if ('timeout' in options) { timeout = options.timeout!; + if ( + retry !== undefined && + retry !== null && + retry.retryCodes.length > 0 + ) { + retry.backoffSettings.initialRpcTimeoutMillis = timeout; + retry.backoffSettings.maxRpcTimeoutMillis = timeout; + retry.backoffSettings.totalTimeoutMillis = timeout; + } } if ('retry' in options) { retry = mergeRetryOptions(retry || ({} as RetryOptions), options.retry!);