druid 当数据库地址配错时,死循环狂刷日志,版本:1.1.22

46scxncf  于 2022-10-27  发布在  Druid
关注(0)|答案(4)|浏览(343)

2020-06-28 16:42:01.042 ERROR com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread:2781 - create connection SQLException, url: jdbc:mysql://mysqldb.saasxx:3306/center_data?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=utf8&useFastDateParsing=false&pinGlobalTxToPhysicalConnection=true&serverTimezone=Hongkong, errorCode 0, state 08S01 com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) ~[druid-1.1.22.jar:1.1.22]
at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) ~[druid-1.1.22.jar:1.1.22]
at com.alibaba.druid.filter.FilterEventAdapter.connection_connect(FilterEventAdapter.java:38) ~[druid-1.1.22.jar:1.1.22]
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.22.jar:1.1.22]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1646) ~[druid-1.1.22.jar:1.1.22]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1710) ~[druid-1.1.22.jar:1.1.22]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2779) [druid-1.1.22.jar:1.1.22]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor107.newInstance(Unknown Source) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_251]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_251]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.20.jar:8.0.20]
... 10 more
Caused by: java.net.UnknownHostException: mysqldb.saasxx
at java.net.InetAddress.getAllByName0(InetAddress.java:1281) ~[?:1.8.0_251]
at java.net.InetAddress.getAllByName(InetAddress.java:1193) ~[?:1.8.0_251]
at java.net.InetAddress.getAllByName(InetAddress.java:1127) ~[?:1.8.0_251]
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.20.jar:8.0.20]
... 10 more

vsdwdz23

vsdwdz231#

数据源配置如下:

Slf4jLogFilter slf4jLogFilter = new Slf4jLogFilter();
            slf4jLogFilter.setStatementCreateAfterLogEnabled(false);
            slf4jLogFilter.setStatementCloseAfterLogEnabled(false);
            slf4jLogFilter.setStatementExecuteAfterLogEnabled(false);
            slf4jLogFilter.setStatementExecuteQueryAfterLogEnabled(false);
            slf4jLogFilter.setStatementExecuteUpdateAfterLogEnabled(false);
            slf4jLogFilter.setStatementExecuteBatchAfterLogEnabled(false);
            slf4jLogFilter.setStatementParameterSetLogEnabled(false);
            slf4jLogFilter.setStatementPrepareAfterLogEnabled(false);
            slf4jLogFilter.setResultSetLogEnabled(false);

            slf4jLogFilter.setStatementExecutableSqlLogEnable(true);
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setUrl(source.getJdbcUrl());
            dataSource.setUsername(source.getUsername());
            dataSource.setPassword(source.getPassword());
            dataSource.setMaxActive(source.getMaxActive());
            dataSource.setTestWhileIdle(true);
            dataSource.setProxyFilters(Arrays.asList(slf4jLogFilter));
ve7v8dk2

ve7v8dk22#

这个似乎也不算个bug,就是这么设计的吧,连接不上说明配置有问题

bqf10yzr

bqf10yzr3#

我觉得设置重连次数connectionErrorRetryAttempts和重连校验间隔时间timeBetweenConnectErrorMillis

vyswwuz2

vyswwuz24#

我觉得设置重连次数connectionErrorRetryAttempts和重连校验间隔时间timeBetweenConnectErrorMillis

大哥 太牛了 冲日志的问题我找了好几天解决方案 你这个可行

相关问题