开发喵星球

若依微服务项目报错解决:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure(111)

1、场景复现

在每次重启数据库的时候,登录系统会报错。第一次会出现用户名不存在等情况,后台会报错,前端依旧可以进入,或者等待时间5分钟,期间不做任何操作,重新登录,这个问题就会复现,复现这个问题最快的方法就是重启数据库。

ruoyi.version:3.6.2
druid.version:1.2.16

2、报错信息

18:49:52.611 [http-nio-9201-exec-5] ERROR druid.sql.Statement - [statementLogError,148] - {conn-10020, pstmt-20048} execute error. select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, 
        d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
        from sys_user u
            left join sys_dept d on u.dept_id = d.dept_id
            left join sys_user_role ur on u.user_id = ur.user_id
            left join sys_role r on r.role_id = ur.role_id

        where u.user_name = ? and u.del_flag = '0'
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
······
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:67)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeaderLocal(SimplePacketReader.java:81)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:63)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:45)
    at com.mysql.cj.protocol.a.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:52)
    at com.mysql.cj.protocol.a.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:41)
    at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:54)
    at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:44)
    at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:575)
    ... 133 common frames omitted

3、解决办法

目前可以通过降低druid版本来解决这个问题。

在根目录下的pom.xml文件中将

    <druid.version>1.2.16</druid.version>

改为
xml
<druid.version>1.2.6</druid.version>

   
分类:Java/OOP 作者:无限繁荣, 吴蓉 发表于:2024-01-27 15:43:52 阅读量:156
<<   >>


powered by kaifamiao