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-878067: Fix retry logic #866

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public void TestLoginWithMaxRetryReached()
{
using (IDbConnection conn = new MockSnowflakeDbConnection())
{
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5";
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5"; // Will be set to the minimum allowed value of 7

conn.ConnectionString = maxRetryConnStr;

Expand All @@ -435,11 +435,11 @@ public void TestLoginWithMaxRetryReached()
}
stopwatch.Stop();

// retry 5 times with starting backoff of 1 second
// but should not delay more than the max possible seconds after 5 retries
// and should not take less time than the minimum possible seconds after 5 retries
Assert.Less(stopwatch.ElapsedMilliseconds, 79 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 1 * 1000);
// retry 7 times with starting backoff of 1 second
// but should not delay more than the max possible seconds after 7 retries
// and should not take less time than the minimum possible seconds after 7 retries
Assert.Less(stopwatch.ElapsedMilliseconds, 164 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 1.9 * 1000);
}
}

Expand Down
16 changes: 8 additions & 8 deletions Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void TestExecuteAsyncWithMaxRetryReached()

using (DbConnection conn = new MockSnowflakeDbConnection(mockRestRequester))
{
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5";
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5"; // Will be set to the minimum allowed value of 7

conn.ConnectionString = maxRetryConnStr;
conn.Open();
Expand All @@ -169,10 +169,10 @@ public void TestExecuteAsyncWithMaxRetryReached()
}
stopwatch.Stop();

// retry 5 times with backoff 1, 2, 4, 8, 16 seconds
// retry 7 times with backoff 1, 2, 4, 8, 16, 16, 16 seconds
// but should not delay more than another 16 seconds
Assert.Less(stopwatch.ElapsedMilliseconds, 51 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 30 * 1000);
Assert.Less(stopwatch.ElapsedMilliseconds, 83 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 62 * 1000);
}
}
}
Expand Down Expand Up @@ -639,7 +639,7 @@ public void TestExecuteWithMaxRetryReached()

using (IDbConnection conn = new MockSnowflakeDbConnection(mockRestRequester))
{
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5";
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5"; // Will be set to the minimum allowed value of 7

conn.ConnectionString = maxRetryConnStr;
conn.Open();
Expand All @@ -660,10 +660,10 @@ public void TestExecuteWithMaxRetryReached()
}
stopwatch.Stop();

// retry 5 times with backoff 1, 2, 4, 8, 16 seconds
// retry 7 times with backoff 1, 2, 4, 8, 16, 16, 16 seconds
// but should not delay more than another 16 seconds
Assert.Less(stopwatch.ElapsedMilliseconds, 51 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 30 * 1000);
Assert.Less(stopwatch.ElapsedMilliseconds, 83 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 62 * 1000);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static IEnumerable<PropertiesTestCase> PropertiesProvider()
{
validateDefaultParameters = true,
clientSessionKeepAlive = false,
timeoutInSec = 0,
timeoutInSec = SFSessionHttpClientProperties.s_retryTimeoutDefault,
insecureMode = false,
disableRetry = false,
forceRetryOn404 = false,
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/Session/SFSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ internal SFSession(
try
{
var extractedProperties = propertiesExtractor.ExtractProperties(properties);
extractedProperties.CheckPropertiesAreValid();
var httpClientConfig = extractedProperties.BuildHttpClientConfig();
ParameterMap = extractedProperties.ToParameterMap();
InsecureMode = extractedProperties.insecureMode;
_HttpClient = HttpUtil.Instance.GetHttpClient(httpClientConfig);
restRequester = new RestRequester(_HttpClient);
extractedProperties.CheckPropertiesAreValid();
connectionTimeout = extractedProperties.TimeoutDuration();
properties.TryGetValue(SFSessionProperty.CLIENT_CONFIG_FILE, out var easyLoggingConfigFile);
_easyLoggingStarter.Init(easyLoggingConfigFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ internal void CheckPropertiesAreValid()
}

// Use the shorter timeout between CONNECTION_TIMEOUT and RETRY_TIMEOUT
if (retryTimeout < timeoutInSec)
// but only if retry timeout is not set to infinite
if (retryTimeout < timeoutInSec && retryTimeout > 0)
{
timeoutInSec = retryTimeout;
}
Expand Down
Loading