Skip to content

Commit

Permalink
fix: ensure abort interrupts running queries (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-congo authored Nov 12, 2024
1 parent d2ddfd5 commit 8f962b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/#semantic-versioning-200).

### :bug: Fixed
- Custom endpoint monitor obeys refresh rate ([PR #1175](https://github.com/aws/aws-advanced-jdbc-wrapper/pull/1175)).
- Abort interrupts running queries ([PR #1182](https://github.com/aws/aws-advanced-jdbc-wrapper/pull/1182))

## [2.5.2] - 2024-11-4
### :bug: Fixed
- Limitless Connection Plugin to reduce extra connections made during new connection creation ([PR #1174](https://github.com/aws/aws-advanced-jdbc-wrapper/pull/1174)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class FailoverConnectionPlugin extends AbstractConnectionPlugin {
Collections.unmodifiableSet(new HashSet<String>() {
{
addAll(SubscribedMethodHelper.NETWORK_BOUND_METHODS);
add("Connection.abort");
add("Connection.close");
add("initHostProvider");
add("connect");
add("forceConnect");
Expand All @@ -92,7 +95,7 @@ public class FailoverConnectionPlugin extends AbstractConnectionPlugin {
protected FailoverMode failoverMode;
private boolean telemetryFailoverAdditionalTopTraceSetting;

private boolean closedExplicitly = false;
private final AtomicBoolean closedExplicitly = new AtomicBoolean(false);
protected boolean isClosed = false;
protected String closedReason = null;
private final RdsUtils rdsHelper;
Expand Down Expand Up @@ -210,7 +213,12 @@ public <T, E extends Exception> T execute(
final Object[] jdbcMethodArgs)
throws E {
if (!this.enableFailoverSetting || canDirectExecute(methodName)) {
return jdbcMethodFunc.call();
T result = jdbcMethodFunc.call();
if (METHOD_ABORT.equals(methodName) || METHOD_CLOSE.equals(methodName)) {
this.closedExplicitly.set(true);
}

return result;
}

if (this.isClosed && !allowedOnClosedConnection(methodName)) {
Expand All @@ -228,6 +236,9 @@ public <T, E extends Exception> T execute(
updateTopology(false);
}
result = jdbcMethodFunc.call();
if (METHOD_ABORT.equals(methodName) || METHOD_CLOSE.equals(methodName)) {
this.closedExplicitly.set(true);
}
} catch (final IllegalStateException e) {
dealWithIllegalStateException(e, exceptionClass);
} catch (final Exception e) {
Expand Down Expand Up @@ -372,7 +383,7 @@ private void initSettings() {
}

private void invalidInvocationOnClosedConnection() throws SQLException {
if (!this.closedExplicitly) {
if (!this.closedExplicitly.get()) {
this.isClosed = false;
this.closedReason = null;
pickNewConnection();
Expand Down Expand Up @@ -736,7 +747,7 @@ protected void invalidateCurrentConnection() {
}

protected void pickNewConnection() throws SQLException {
if (this.isClosed && this.closedExplicitly) {
if (this.isClosed && this.closedExplicitly.get()) {
LOGGER.fine(() -> Messages.get("Failover.transactionResolutionUnknownError"));
return;
}
Expand All @@ -753,6 +764,9 @@ protected void pickNewConnection() throws SQLException {
}

protected boolean shouldExceptionTriggerConnectionSwitch(final Throwable t) {
if (this.closedExplicitly.get()) {
return false;
}

if (!isFailoverEnabled()) {
LOGGER.fine(() -> Messages.get("Failover.failoverDisabled"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class AsynchronousMethodsHelper {
public static final List<String> ASYNCHRONOUS_METHODS = Arrays.asList(
"Statement.cancel",
"PreparedStatement.cancel"
"PreparedStatement.cancel",
"Connection.abort"
);
}

0 comments on commit 8f962b6

Please # to comment.