一、问题背景
WebLogic 14c配置了 MySQL 数据源(数据库使用的是MySQL的开源版本 - MariaDB),数据源其中一个 Target 为 WebLogic 应用域的一个受管服务器实例 - appServer1,并且为了增强 WebLogic JDBC Pool 里面的数据库连接的可用性,还在数据源的【连接池】 - 【高级】选项中,勾选并开启了【测试频率】,默认值为 120 秒。
【测试频率】参数的含义:WebLogic Server 实例对未用(的数据库)连接进行测试的间隔秒数(要求指定“测试表名称”) 。未通过测试的(数据库)连接将被关闭, 然后(再)将它们重新打开,以重新建立有效的物理连接。如果测试再次失败, 则此连接将被关闭。默认 120 秒。
配置该参数后,发现 appServer1 实例的控制台日志,一直在刷下面的报错信息:
<2023-5-30 上午06时55分31,883秒 CST> <Error> <JDBC> <BEA-001112> <Test "select count(*) from mydbs.employee" set up for pool "mydbs" failed with exception: "com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 118,981 milliseconds ago. The last packet sent successfully to the server was 118,981 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.".>
<2023-5-30 上午06时57分31,916秒 CST> <Error> <JDBC> <BEA-001112> <Test "select count(*) from mydbs.employee" set up for pool "mydbs" failed with exception: "com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 119,025 milliseconds ago. The last packet sent successfully to the server was 119,025 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.".>
<2023-5-30 上午06时59分31,885秒 CST> <Error> <JDBC> <BEA-001112> <Test "select count(*) from mydbs.employee" set up for pool "mydbs" failed with exception: "com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 118,962 milliseconds ago. The last packet sent successfully to the server was 118,963 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.".>
<2023-5-30 上午07时01分31,892秒 CST> <Error> <JDBC> <BEA-001112> <Test "select count(*) from mydbs.employee" set up for pool "mydbs" failed with exception: "com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 119,000 milliseconds ago. The last packet sent successfully to the server was 119,000 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.".>
<2023-5-30 上午07时03分31,885秒 CST> <Error> <JDBC> <BEA-001112> <Test "select count(*) from mydbs.employee" set up for pool "mydbs" failed with exception: "com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 118,985 milliseconds ago. The last packet sent successfully to the server was 118,985 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.".>
二、问题排查
首先,在MOS中查询与错误码 BEA-001112 有关的Document,并未查询到与我上免报错一样的信息。
第二步,在MOS上开SR,申请ORACLE工程师技术支持,工程师给的可能性(MariaDB服务配置的时区与系统时区不一致、MySQL Connector/J版本-社区版本、企业版本),最后证明都与报错信息无关。关于时区的问题,ORACLE工程师给了三个参数,配置在WebLogic控制台的JDBC连接池的属性或者系统属性参数栏里面来统一时区,这里给大家分享一下。
preserveInstants=true
connectionTimeZone=SERVER
forceConnectionTimeZoneToSession=false
第三步,根据报错信息,将 MariaDB 的配置文件 my.cnf 里面的 wait_timeout 参数(配置为10秒)修改为 60 秒,重启 MariaDB 服务,发现报错信息依旧。
第四步,将 MariaDB 的配置文件 my.cnf 里面的 wait_timeout 参数调整为 130 秒后,发现报错信息不再刷新了。至此,问题解决。
三、问题复盘
可以发现,这次问题的根本原因,是 WebLogic 控制台里面配置的数据库连接可用性的主动式探测的时间间隔,即【测试频率】(Test Frequency),与 MariaDB 服务配置的 wait_timeout 超时时间存在逻辑冲突导致。所以,如果在 WebLogic 的数据源配置里面启动了数据库连接可用性的主动探测,那么这个测试频率需要小于或者等于 MySQL 服务配置 wait_timeout 参数。
下面是网上关于 MySQL 数据库 wait_timeout 参数含义的说明:
wait_timeout参数,定义对于非交互式连接,服务端等待数据的最长时间。如果超过这个时间,服务端仍然没有收到数据,则会关闭连接。