From 279d37306e27d2cc2b4d9716a1ad46174ce742c6 Mon Sep 17 00:00:00 2001 From: sergiyvamz Date: Thu, 28 Nov 2024 16:44:01 -0800 Subject: [PATCH] clear closed Hikari connections --- .../jdbc/plugin/OpenedConnectionTracker.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/OpenedConnectionTracker.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/OpenedConnectionTracker.java index 311e43839..3671a5b76 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/OpenedConnectionTracker.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/OpenedConnectionTracker.java @@ -199,7 +199,20 @@ private void logConnectionQueue(final String host, final Queue { - queue.removeIf(connectionWeakReference -> Objects.equals(connectionWeakReference.get(), null)); + queue.removeIf(connectionWeakReference -> { + final Connection conn = connectionWeakReference.get(); + if (conn == null) { + return true; + } + if (conn.getClass().getSimpleName().equals("HikariProxyConnection")) { + try { + return conn.isClosed(); + } catch (SQLException ex) { + return false; + } + } + return false; + }); }); }