diff --git a/Snowflake.Data/Core/HttpUtil.cs b/Snowflake.Data/Core/HttpUtil.cs index f835b7eb5..fa52348e8 100755 --- a/Snowflake.Data/Core/HttpUtil.cs +++ b/Snowflake.Data/Core/HttpUtil.cs @@ -406,7 +406,7 @@ protected override async Task SendAsync(HttpRequestMessage } else if (childCts != null && childCts.Token.IsCancellationRequested) { - logger.Warn($"Http request timeout. Retry the request after {backOffInSec} sec."); + logger.Warn($"Http request timeout. Retry the request after max {backOffInSec} sec."); } else { @@ -465,7 +465,7 @@ protected override async Task SendAsync(HttpRequestMessage logger.Info("Response returned was null."); } - if (restTimeout.TotalSeconds > 0 && totalRetryTime > restTimeout.TotalSeconds) + if (restTimeout.TotalSeconds > 0 && totalRetryTime >= restTimeout.TotalSeconds) { logger.Debug($"stop retry as connection_timeout {restTimeout.TotalSeconds} sec. reached"); if (response != null) @@ -478,6 +478,12 @@ protected override async Task SendAsync(HttpRequestMessage throw new OperationCanceledException(errorMessage); } + if (restTimeout.TotalSeconds > 0 && totalRetryTime + backOffInSec > restTimeout.TotalSeconds) + { + // No need to wait more than necessary if it can be avoided. + backOffInSec = (int)restTimeout.TotalSeconds - totalRetryTime; + } + retryCount++; if ((maxRetryCount > 0) && (retryCount > maxRetryCount)) { @@ -516,15 +522,6 @@ protected override async Task SendAsync(HttpRequestMessage // Multiply sleep by 2 for non-login requests backOffInSec *= 2; } - - totalRetryTime = (int)((DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - startTimeInMilliseconds) / 1000); - if ((restTimeout.TotalSeconds > 0) && (totalRetryTime + backOffInSec > restTimeout.TotalSeconds)) - { - // No need to wait more than necessary if it can be avoided. - // If the rest timeout will be reached before the next back-off, - // then use the remaining connection timeout. - backOffInSec = Math.Min(backOffInSec, (int)restTimeout.TotalSeconds - totalRetryTime + 1); - } } } }