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

re-interrupt the current thread, in order to restore the thread's interrupt status. #204

Merged
merged 3 commits into from
Mar 29, 2017
Merged
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
2 changes: 2 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6882,6 +6882,8 @@ public void run() {
while (--secondsRemaining > 0);
}
catch (InterruptedException e) {
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ public void run() {
while (--secondsRemaining > 0);
}
catch (InterruptedException e) {
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,8 @@ else if (null == currentPrimaryPlaceHolder) {
Thread.sleep(sleepInterval);
}
catch (InterruptedException e) {
// continue if the thread is interrupted. This really should not happen.
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
}
sleepInterval = (sleepInterval < 500) ? sleepInterval * 2 : 1000;
}
Expand Down Expand Up @@ -3531,7 +3532,8 @@ else if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDi
Thread.sleep(sleepInterval);
}
catch (InterruptedException e1) {
// continue if the thread is interrupted. This really should not happen.
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
}
sleepInterval = sleepInterval * 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Logger;

import javax.sql.ConnectionEvent;
Expand Down Expand Up @@ -510,4 +513,45 @@ public void testGetSchema() throws SQLException {
SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString);
conn.getSchema();
}

static Boolean isInterrupted = false;

/**
* Test thread's interrupt status is not cleared.
*
* @throws InterruptedException
*/
@Test
public void testThreadInterruptedStatus() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
SQLServerDataSource ds = new SQLServerDataSource();

ds.setURL(connectionString);
ds.setServerName("invalidServerName" + UUID.randomUUID());
ds.setLoginTimeout(5);

try {
ds.getConnection();
}
catch (SQLException e) {
isInterrupted = Thread.currentThread().isInterrupted();
}
}
};

ExecutorService executor = Executors.newFixedThreadPool(1);
Future<?> future = executor.submit(runnable);

Thread.sleep(1000);

// interrupt the thread in the Runnable
future.cancel(true);

Thread.sleep(8000);

executor.shutdownNow();

assertTrue(isInterrupted, "Thread's interrupt status is not set.");
}
}