Skip to content

Commit

Permalink
Fail fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery-Wasty committed Sep 20, 2024
1 parent ca23e4e commit c9d02de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial
/**
* Back off interval in ms for retries
*/
static final int BACKOFF_INTERVAL = 100;
static final int BACKOFF_INTERVAL = 500;

/** Current limit for this particular connection. */
private Boolean enablePrepareOnFirstPreparedStatementCall = null;
Expand Down Expand Up @@ -3528,9 +3528,11 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu

// We only get here when we failed to connect, but are going to re-try
// After trying to connect to both servers fails, sleep for a bit to prevent clogging
// the network with requests, then update sleep interval for next iteration (max 1 second interval)
// We have to sleep for every attempt in case of non-dbMirroring scenarios (including multisubnetfailover),
// Whereas for dbMirroring, we sleep for every two attempts as each attempt is to a different server.
// the network with requests, then update sleep interval for next iteration (to a maximum specified by
// connectRetryInterval [default 10]). We have to sleep for every attempt in case of non-dbMirroring
// scenarios (including multisubnetfailover), whereas for dbMirroring, we sleep for every two attempts
// as each attempt is to a different server.

// Make sure there's enough time to do another retry
if (!isDBMirroring || (isDBMirroring && (0 == attemptNumber % 2))
&& (attemptNumber < connectRetryCount && connectRetryCount != 0) && timerRemaining(
Expand All @@ -3546,7 +3548,12 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
}

sleepForInterval(fedauthRetryInterval);
fedauthRetryInterval = (fedauthRetryInterval < 500) ? fedauthRetryInterval * 2 : 1000;
int connectRetryIntervalInSeconds = (int) TimeUnit.SECONDS.toMillis(connectRetryInterval);

fedauthRetryInterval *= 2; // Double each time
if (fedauthRetryInterval > connectRetryIntervalInSeconds) {
fedauthRetryInterval = connectRetryIntervalInSeconds; // To a maximum of connectRetryInterval

Check warning on line 3555 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L3555

Added line #L3555 was not covered by tests
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testBasicConnectionAAD() throws Exception {

basicReconnect("jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";user="
+ azureUserName + ";password=" + azurePassword
+ ";loginTimeout=90;Authentication=ActiveDirectoryPassword");
+ ";loginTimeout=90;Authentication=ActiveDirectoryPassword;");
retry = THROTTLE_RETRY_COUNT + 1;
} catch (Exception e) {
if (e.getMessage().matches(TestUtils.formatErrorMsg("R_crClientAllRecoveryAttemptsFailed"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,6 @@ public void testSqlServerBulkCopyCachingConnectionLevelMultiThreaded() throws Ex

((HashMap<?, ?>) bulkcopyCache).clear();

TimerTask task = new TimerTask() {
public void run() {
((HashMap<?, ?>) bulkcopyCache).clear();
fail(TestResource.getResource("R_executionTooLong"));
}
};
Timer timer = new Timer("Timer");
timer.schedule(task, timeOut); // Run a timer to help us exit if we get deadlocked

final CountDownLatch countDownLatch = new CountDownLatch(NUMBER_SIMULTANEOUS_INSERTS);
Runnable runnable = () -> {
Expand Down

0 comments on commit c9d02de

Please sign in to comment.