16

I'm using hikari pool connection through play framework and mariadb client and since I've updated them (play 2.6.5 -> 2.6.6 and mariadb 2.1.1 -> 2.1.2 but not sure it's related) regularly I've got the following error:

HikariPool-1 - Failed to validate connection org.mariadb.jdbc.MariaDbConnection@31124a47 (Connection.setNetworkTimeout cannot be called on a closed connection)
    at com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:184)
    at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:172)
    at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:146)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:85)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
    at play.api.db.DefaultDatabase.withConnection(Databases.scala:152)
    at play.api.db.DefaultDatabase.withConnection(Databases.scala:148)

I've found a related issue here and tried to change the idleTimeout and maxLifetime to 2 and 5 minutes but the error still happened.

I'm using HikariCP 2.7.1, play 2.6.6 and mariadb-java-client 2.1.2

Maxence Cramet
  • 552
  • 1
  • 5
  • 17

2 Answers2

18

Although you write that you had no success solving this issue by changing the maxLifetime value, I wanted to note that it actually worked for me. Putting its value to 590000 has removed the warnings from my log file.

The maxLifetime (in milliseconds) value of your client should be less than the wait_timeout (in seconds) value of your MySQL instance. This way the client will always terminate the connection before the database tries to. The other way around, the client will try to act upon a closed connection and you will get the above mentioned warnings in your log file.

To see the wait_timeout value of your MySQL instance, you can use the following query:

SHOW VARIABLES like '%timeout%';

The default maxLifetime value for MariaDB should be 28800, but I noticed that 600 can be in place because of MySQL config files being loaded.

I should note that I have no other explicit hikari configuration in place except for a maximum-pool-size of 50.

I got the inspiration from: https://github.com/brettwooldridge/HikariCP/issues/856 by the way. Other very useful resources are: https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby and https://mariadb.com/kb/en/library/server-system-variables/#wait_timeout

Ostecke
  • 1,469
  • 12
  • 13
  • In this case i have configured wait_timeout higher value. But i confused whether it is GLOBAL or SESSION variable in mysql. Only GLOBAL i could change. – Namjith Aravind Nov 04 '19 at 12:15
0

Try to configure "keepaliveTime" configuration.

spring.datasource.hikari.keepaliveTime=240000

"This property controls how frequently HikariCP will attempt to keep a connection alive, in order to prevent it from being timed out by the database or network infrastructure. This value must be less than the maxLifetime value. A "keepalive" will only occur on an idle connection. When the time arrives for a "keepalive" against a given connection, that connection will be removed from the pool, "pinged", and then returned to the pool. The 'ping' is one of either: invocation of the JDBC4 isValid() method, or execution of the connectionTestQuery. Typically, the duration out-of-the-pool should be measured in single digit milliseconds or even sub-millisecond, and therefore should have little or no noticeable performance impact. The minimum allowed value is 30000ms (30 seconds), but a value in the range of minutes is most desirable. Default: 0 (disabled)"

https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby

Pasquale Vitale
  • 569
  • 1
  • 6
  • 15