2

Is it possible to enable leak detection in version 2.3.9? As I previously said in this question Hibernate was using version 2.3.3 of HikariCP. As of February 2016, they have upgraded the version of HikariCP, but unfortunately to version 2.3.9

I need to enable the detection of leaks in order to fix them. I have added the following lines to hibernate configuration file:

<property name="hibernate.hikari.maximumPoolSize">30</property>
<property name="hibernate.hikari.idleTimeout">30000</property>
<property name="hibernate.hikari.dataSource.leakDetectionThreshold">30000</property>   

The first two lines work and can be seen in the debug log, but when I add the third one I can't run the application. I have also tried to add this using code, but it still doesn't work. I get the following error:

HHH000130: Instantiating explicit connection provider: org.hibernate.hikaricp.internal.HikariCPConnectionProvider
Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]Initial SessionFactory creation failed.Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Community
  • 1
  • 1
George Sofianos
  • 440
  • 1
  • 7
  • 17

2 Answers2

11

leakDetectionThreshold is not property of data source, it is hikaricp specific. try removing word 'dataSource' as:

<property name="hibernate.hikari.leakDetectionThreshold">30000</property>
Nitin
  • 1,582
  • 11
  • 12
  • Thanks, that worked! I was trying to add this to hibernate via code without the datasource but it wasn't working. But inside the cfg.xml I never tried to use this without dataSource. I think every source I found on google had dataSource in the cfg.xml. – George Sofianos Mar 03 '16 at 09:16
0

For me, leakDetectionThreshold property didn't work as expected. Try increasing the rest of the 'timeout' properties and see what works for you.

private DataSource tenantDataSource() {
    HikariConfig config = new HikariConfig();
    config.setValidationTimeout(60000);
    config.setConnectionTimeout(60000);
    config.setIdleTimeout(60000);
    config.setInitializationFailTimeout(60000);
    config.setLeakDetectionThreshold(60000);
    ...
    the rest of the Hikari configuration
    ...
    return HikariDataSource(config);
}

Of course, you can also change these values in .yml files:

spring:
    datasource:
        hikari:
            validation-timeout: 60000
            leak-detection-threshold: 60000
            connection-timeout: 60000
            idle-timeout: 60000
            initialization-fail-timeout: 60000

Still try to investigate why is that happening, since it is not normal to get these exceptions often.

Also, take a look at this question

dextertron_
  • 921
  • 1
  • 10
  • 19
  • 1
    From Hikari documentation: "This property controls the amount of time that a connection can be out of the pool before a message is logged indicating a possible connection leak. A value of 0 means leak detection is disabled. Lowest acceptable value for enabling leak detection is 2000 (2 seconds). Default: 0". I do not recommend this setting. – dextertron_ Jul 09 '20 at 10:11
  • Why not recommend it? – Ethan Solomon Jul 08 '21 at 12:38