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

Fix | Fix SQLServerConnection.abort() API behavior to clear resources consistently #983

Merged
merged 4 commits into from
Mar 13, 2019
Merged
Changes from 3 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
30 changes: 18 additions & 12 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3169,16 +3169,10 @@ public void rollback() throws SQLServerException {
public void abort(Executor executor) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "abort", executor);

// nop if connection is closed
// no-op if connection is closed
if (isClosed())
return;

if (null == executor) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
Object[] msgArgs = {"executor"};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
}

// check for callAbort permission
SecurityManager secMgr = System.getSecurityManager();
if (secMgr != null) {
Expand All @@ -3191,11 +3185,19 @@ public void abort(Executor executor) throws SQLException {
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
}
}
if (null == executor) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
Object[] msgArgs = {"executor"};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
} else {

setState(State.Closed);
// Always report the connection as closed for any further use, no matter
// what happens when we try to clean up the physical resources associated
// with the connection using executor.
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
setState(State.Closed);

if (null != tdsChannel && null != executor)
executor.execute(() -> tdsChannel.close());
executor.execute(() -> clearConnectionResources());
}

loggerExternal.exiting(getClassNameLogging(), "abort");
}
Expand All @@ -3209,6 +3211,12 @@ public void close() throws SQLServerException {
// with the connection.
setState(State.Closed);

clearConnectionResources();

loggerExternal.exiting(getClassNameLogging(), "close");
}

private void clearConnectionResources() {
if (sharedTimer != null) {
sharedTimer.removeRef();
sharedTimer = null;
Expand All @@ -3232,8 +3240,6 @@ public void close() throws SQLServerException {
cleanupPreparedStatementDiscardActions();

ActivityCorrelator.cleanupActivityId();

loggerExternal.exiting(getClassNameLogging(), "close");
}

// This function is used by the proxy for notifying the pool manager that this connection proxy is closed
Expand Down