From 50620134b5fac759decb1c44c13667541e01bdcc Mon Sep 17 00:00:00 2001 From: barreiro Date: Thu, 22 Jul 2021 16:22:54 +0100 Subject: [PATCH] Expose Agroal feature: enhanced leak report --- .../quarkus/agroal/runtime/AgroalEventLoggingListener.java | 5 +++++ .../quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java | 6 ++++++ .../main/java/io/quarkus/agroal/runtime/DataSources.java | 1 + 3 files changed, 12 insertions(+) diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/AgroalEventLoggingListener.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/AgroalEventLoggingListener.java index 1761696f081bb..a8fdce4ad6198 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/AgroalEventLoggingListener.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/AgroalEventLoggingListener.java @@ -41,6 +41,11 @@ public void onConnectionCreation(Connection connection) { log.tracev("{0}: Created connection {1}", datasourceName, connection); } + @Override + public void onConnectionLeak(Connection connection, Thread thread) { + log.infov("{0}: Connection leak of {1}", datasourceName, connection); + } + @Override public void onConnectionReap(Connection connection) { log.tracev("{0}: Closing idle connection {1}", datasourceName, connection); diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java index 34c7556b662c5..b695807d275ca 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java @@ -76,6 +76,12 @@ public class DataSourceJdbcRuntimeConfig { @ConfigItem public Optional transactionIsolationLevel = Optional.empty(); + /** + * Collect and display extra troubleshooting info on leaked connections. + */ + @ConfigItem + public boolean extendedLeakReport; + /** * When enabled Agroal will be able to produce a warning when a connection is returned * to the pool without the application having closed all open statements. diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java index e9bb1fe3a6cf5..dbd0f387d6ba0 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java @@ -292,6 +292,7 @@ public boolean isValid(Connection connection) { if (dataSourceJdbcRuntimeConfig.maxLifetime.isPresent()) { poolConfiguration.maxLifetime(dataSourceJdbcRuntimeConfig.maxLifetime.get()); } + poolConfiguration.enhancedLeakReport(dataSourceJdbcRuntimeConfig.extendedLeakReport); } public DataSourceBuildTimeConfig getDataSourceBuildTimeConfig(String dataSourceName) {