Hikari:由于连接已关闭,无法验证连接 [英] Hikari: Failed to validate connection because connection is closed

查看:303
本文介绍了Hikari:由于连接已关闭,无法验证连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过游戏框架和mariadb客户端使用hikari池连接,并且由于我已定期更新它们(游戏2.6.5-> 2.6.6和mariadb 2.1.1-> 2.1.2,但不确定是否相关)我遇到以下错误:

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)

我在此处找到了一个相关问题,并尝试更改了idleTimeout和maxLifetime2至5分钟,但错误仍然发生.

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.

我正在使用HikariCP 2.7.1,播放2.6.6和mariadb-java-client 2.1.2

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

推荐答案

尽管您写道通过更改 maxLifetime 值无法成功解决此问题,但我想指出它实际上适用于我.将其值设置为 590000 已从我的日志文件中删除了警告.

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.

客户端的 maxLifetime (以毫秒为单位)值应小于MySQL实例的 wait_timeout (以秒为单位)值.这样,客户端将始终在数据库尝试之前终止连接.反之,客户端将尝试对关闭的连接进行操作,您将在日志文件中收到上述警告.

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.

要查看您的MySQL实例的 wait_timeout 值,可以使用以下查询:

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

显示变量,例如'%timeout%';

MariaDB的默认 maxLifetime 值应为 28800 ,但我注意到 600 可以就位,因为正在加载MySQL配置文件

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.

我应该注意,除了 50 最大池大小之外,我没有其他显式的hikari配置.

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

我从以下方面得到了灵感: https://github.com/brettwooldridge/HikariCP/issues/856 .其他非常有用的资源是: https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby https://mariadb.com/kb/en/library/server-system-variables/#wait_timeout

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

这篇关于Hikari:由于连接已关闭,无法验证连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆