Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1739483 improve calculation of time to wait before retry #1046

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions Snowflake.Data/Core/HttpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ protected override async Task<HttpResponseMessage> 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
{
Expand Down Expand Up @@ -465,7 +465,7 @@ protected override async Task<HttpResponseMessage> 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)
Expand All @@ -478,6 +478,12 @@ protected override async Task<HttpResponseMessage> 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;
sfc-gh-knozderko marked this conversation as resolved.
Show resolved Hide resolved
}

retryCount++;
if ((maxRetryCount > 0) && (retryCount > maxRetryCount))
{
Expand Down Expand Up @@ -516,15 +522,6 @@ protected override async Task<HttpResponseMessage> 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);
}
}
}
}
Expand Down
Loading