diff --git a/wrapper/src/main/java/software/amazon/jdbc/HostListProviderService.java b/wrapper/src/main/java/software/amazon/jdbc/HostListProviderService.java index b2f6b5353..2476dcda8 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/HostListProviderService.java +++ b/wrapper/src/main/java/software/amazon/jdbc/HostListProviderService.java @@ -38,4 +38,6 @@ public interface HostListProviderService { Dialect getDialect(); HostSpecBuilder getHostSpecBuilder(); + + boolean isInTransaction(); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java index eb677a1c2..4017b09b3 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java +++ b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java @@ -360,12 +360,17 @@ protected List queryForTopology(final Connection conn) throws SQLExcep new Object[] {e.getMessage()})); } + boolean shouldCommit = !conn.getAutoCommit() && !this.hostListProviderService.isInTransaction(); + try (final Statement stmt = conn.createStatement(); final ResultSet resultSet = stmt.executeQuery(this.topologyQuery)) { return processQueryResults(resultSet); } catch (final SQLSyntaxErrorException e) { throw new SQLException(Messages.get("RdsHostListProvider.invalidQuery"), e); } finally { + if (shouldCommit) { + conn.commit(); + } if (networkTimeout == 0 && !conn.isClosed()) { conn.setNetworkTimeout(networkTimeoutExecutor, networkTimeout); }