[alibaba/druid]db2 偶发com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException ,如何避免这样的错误?

2025-11-05 805 views
8

配置如下: druid: filters: stat max-active: 20 initial-size: 3 max-wait: 60000 min-idle: 1 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 validation-query: values 1 test-while-idle: true test-on-borrow: true test-on-return: false pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 异常堆栈: 2023-10-13T11:47:16+08:00 com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][4.32.28] A communication error occurred during operations on the connection's underlying socket, socket input stream, 2023-10-13T11:47:16+08:00 or socket output stream. Error location: Reply.fill() - socketInputStream.read (-1). Message: Read timed out. ERRORCODE=-4499, SQLSTATE=08001 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.am.b7.a(b7.java:338) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.a.a(a.java:577) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.a.a(a.java:561) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.a.a(a.java:556) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.a.b(a.java:1727) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.y.b(y.java:264) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.y.c(y.java:342) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.y.c(y.java:455) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.y.v(y.java:1230) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.ab.d(ab.java:108) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.p.c(p.java:44) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.av.j(av.java:162) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.am.lc.an(lc.java:2300) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.am.ld.a(ld.java:4822) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.am.ld.b(ld.java:4338) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.am.ld.bg(ld.java:3004) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.am.ld.execute(ld.java:2979) 2023-10-13T11:47:16+08:00 at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3446) 2023-10-13T11:47:16+08:00 at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:434) 2023-10-13T11:47:16+08:00 at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3444) 2023-10-13T11:47:16+08:00 at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:158) 2023-10-13T11:47:16+08:00 at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:483) 2023-10-13T11:47:16+08:00 at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source) 2023-10-13T11:47:16+08:00 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2023-10-13T11:47:16+08:00 at java.lang.reflect.Method.invoke(Method.java:498) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) 2023-10-13T11:47:16+08:00 at com.sun.proxy.$Proxy474.execute(Unknown Source) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) 2023-10-13T11:47:16+08:00 at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source) 2023-10-13T11:47:16+08:00 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2023-10-13T11:47:16+08:00 at java.lang.reflect.Method.invoke(Method.java:498) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:64) 2023-10-13T11:47:16+08:00 at com.sun.proxy.$Proxy472.query(Unknown Source) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) 2023-10-13T11:47:16+08:00 at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) 2023-10-13T11:47:16+08:00 at com.sun.proxy.$Proxy471.query(Unknown Source) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) 2023-10-13T11:47:16+08:00 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) 2023-10-13T11:47:16+08:00 at sun.reflect.GeneratedMethodAccessor100.invoke(Unknown Source) 2023-10-13T11:47:16+08:00 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2023-10-13T11:47:16+08:00 at java.lang.reflect.Method.invoke(Method.java:498) 2023-10-13T11:47:16+08:00 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) 2023-10-13T11:47:16+08:00 at com.sun.proxy.$Proxy157.selectOne(Unknown Source) 2023-10-13T11:47:16+08:00 at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160) 2023-10-13T11:47:16+08:00 at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:89) 2023-10-13T11:47:16+08:00 at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) 2023-10-13T11:47:16+08:00 at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) 2023-10-13T11:47:16+08:00 at com.sun.proxy.$Proxy189.getId(Unknown Source) ... 2023-10-13T11:47:16+08:00 Caused by: java.net.SocketTimeoutException: Read timed out 2023-10-13T11:47:16+08:00 at java.net.SocketInputStream.socketRead0(Native Method) 2023-10-13T11:47:16+08:00 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) 2023-10-13T11:47:16+08:00 at java.net.SocketInputStream.read(SocketInputStream.java:171) 2023-10-13T11:47:16+08:00 at java.net.SocketInputStream.read(SocketInputStream.java:141) 2023-10-13T11:47:16+08:00 at com.ibm.db2.jcc.t4.y.b(y.java:230) 2023-10-13T11:47:16+08:00 ... 163 common frames omitted

回答

9

druid版本使用的是1.2.19

6

Caused by: java.net.SocketTimeoutException: Read timed out 应该是你的查询耗时比较久,设置一下socketTimeout参数,默认是10秒,在你的场景可能不够用。 设置成300秒观察一下。

9

@lizongbo 试了下socketTimeout参数,只是异常时间加长了,估计底层已经断开了

7

大概率是连接空闲时间超过限制,被防火墙或数据库服务端直接Reset了,客户端无感继续使用无效连接所致。 建议druid配置keepAlive为true