From bbb2f708dd86d681a02237aa1b7c366668af37d4 Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Sat, 14 Apr 2018 10:37:34 +0200 Subject: [PATCH] ARTEMIS-1806 JDBC Connection leaks The JDBC Connection leaks on: - JDBCFileUtils::getDBFileDriver(DataSource, SQLProvider) - SharedStoreBackupActivation.FailbackChecker::run on a failed awaitLiveStatus --- .../activemq/artemis/jdbc/store/file/JDBCFileUtils.java | 8 ++++++-- .../core/server/impl/SharedStoreBackupActivation.java | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCFileUtils.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCFileUtils.java index 5834852699..803584b55c 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCFileUtils.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCFileUtils.java @@ -44,8 +44,12 @@ class JDBCFileUtils { } static JDBCSequentialFileFactoryDriver getDBFileDriver(DataSource dataSource, SQLProvider provider) throws SQLException { - JDBCSequentialFileFactoryDriver dbDriver; - if (POSTGRESQL.equals(PropertySQLProvider.Factory.investigateDialect(dataSource.getConnection()))) { + final JDBCSequentialFileFactoryDriver dbDriver; + final PropertySQLProvider.Factory.SQLDialect sqlDialect; + try (Connection connection = dataSource.getConnection()) { + sqlDialect = PropertySQLProvider.Factory.investigateDialect(connection); + } + if (POSTGRESQL.equals(sqlDialect)) { dbDriver = new PostgresSequentialSequentialFileDriver(dataSource, provider); } else { dbDriver = new JDBCSequentialFileFactoryDriver(dataSource, provider); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java index 913cc7b1db..383f93fbdd 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java @@ -215,8 +215,11 @@ public final class SharedStoreBackupActivation extends Activation { // ensure that the server to which we are failing back actually starts fully before we restart nodeManager.start(); - nodeManager.awaitLiveStatus(); - nodeManager.stop(); + try { + nodeManager.awaitLiveStatus(); + } finally { + nodeManager.stop(); + } synchronized (failbackCheckerGuard) { if (cancelFailBackChecker || !sharedStoreSlavePolicy.isRestartBackup())