From c19508c47ad4f5491432084bfcf4b4ba835d5e86 Mon Sep 17 00:00:00 2001 From: Park Jaeon Date: Mon, 28 Oct 2024 16:23:49 +0900 Subject: [PATCH] fix: commit transaction after topology query --- .../java/software/amazon/jdbc/HostListProviderService.java | 2 ++ .../amazon/jdbc/hostlistprovider/RdsHostListProvider.java | 5 +++++ 2 files changed, 7 insertions(+) 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); }