Skip to content

druid1.2.8以上的版本中jdbc:mysql:loadbalance://执行超过10秒会报超时错误 #5396

Closed

Description

@lizhuangs

1.2.8以上版本,当协议是jdbc:mysql:loadbalance://时,查询超过10秒就会报错.
经过验证发现1.2.8以上的版本中新增了一个socketTimeout属性,而这个属性在1.2.8以上的版本中无论是connectionProperties中设置还是直接在url中设置都不生效.只能在获取到数据源对象后,手动设置一下才可以.
如果我把协议换成jdbc:mysql://时,则1.2.8以上在url中加上socketTimeout也可以支持.但是这样就不支持集群了,只能固定一个数据库地址查询.
如果把druid换成1.2.8版本,则不需要配置socketTimeout这些属性就不会报错,推测1.2.8及以下的版本是读取的maxWait这个属性.
`com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet successfully received from the server was 10,090 milliseconds ago. The last packet sent successfully to the server was 10,090 milliseconds ago.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:974)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1024)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.mysql.cj.jdbc.ha.MultiHostConnectionProxy$JdbcInterfaceProxy.invoke(MultiHostConnectionProxy.java:105)
at com.sun.proxy.$Proxy88.executeQuery(Unknown Source)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:213)`

Activity

  1. lizongbo commented on Sep 30, 2023

    @lizongbo
    Collaborator

    核实是initFromUrlOrProperties方法,没有判断loadbalance格式的url,没有识别到参数。
    我来加一下适配
    if (jdbcUrl.startsWith("jdbc:mysql://") || jdbcUrl.startsWith("jdbc:mysql:loadbalance://")) {

  2. kimmking commented on Oct 5, 2023

    @kimmking
    Collaborator

    请使用最新版本。

  3. lizhuangs commented on Oct 7, 2023

    @lizhuangs
    Author

    请使用最新版本。

    还没发布呃

  4. lizongbo commented on Oct 8, 2023

    @lizongbo
    Collaborator

    请使用最新版本。

    还没发布呃

    1.2.20已经发布,请更新

  5. lizhuangs commented on Oct 9, 2023

    @lizhuangs
    Author

    测试可以了,感谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions