19

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

3
  • 1
    Hey @Maxence, did you figure out how to fix it? Commented Nov 2, 2017 at 2:34
  • 1
    @jNewbie, no... Commented Nov 6, 2017 at 14:04
  • I tried to change my driver to use the mysql one but still not working Commented Nov 24, 2017 at 13:25

2 Answers 2

19

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
2

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

1 Comment

it worked, my MySQL's wait_timeout is 28800 (8 hours), while Hikari's maxLifetime default is 1800000 (30 minutes), but still has error until set keepaliveTime=60000

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.