alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.9k stars 8.57k forks source link

2.x版本出现:An I/O error occurred while sending to the backend #5098

Open changuoqiang opened 1 year ago

changuoqiang commented 1 year ago

运行环境:

openjdk 11.0.4 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)

tomcat 9.0.16

PostgreSQL 11.5 (Debian 11.5-1+deb10u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit

JDBC driver pgJDBC 42.2.5

原本使用druid 1.1.19版本,最近升级到最新版本1.2.15后,只升级了druid,其他没有改变,出现以下问题:

tomcat应用程序日志出现: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

postgresql数据库日志出现: unexpected EOF on client connection with an open transaction

应用程序闲置一段时间会出现此问题 ,比如晚上没人使用,早上第一次访问时应用程序会出错,但再次访问就不再出错了。

这个错误每天都出现几次,现在换回了1.1.24版本,问题消失不见了。

kimmking commented 1 year ago

1、请提供详细的异常堆栈。 2、也请检查两种情况下,是否pg驱动版本不一致。

changuoqiang commented 1 year ago

1、请提供详细的异常堆栈。 2、也请检查两种情况下,是否pg驱动版本不一致。

1、附件提供日志片段 2、pgJDBC驱动版本一致 druid.txt

enchanterzj commented 1 year ago

我也存在相同的问题,最后也是将druid的版本改到1.1.24该问题不再重现。 1、期间尝试过对test-on-borrow和test-on-return改为true,未能解决; 2、pg的jdbc驱动版本42.3.8,版本一致。也改过驱动版本到最新,排除了pg的驱动问题; 3、目前验证sql主要是select count(1) from table,在table数据量大于30万之后能复现此报错; 4、遇到的错误druid版本是1.2.14,也尝试过1.2.16,问题相同; 5、报错日志(druid版本1.2.14,pg_jdbc42.3.8)片段如下:### Error querying database. Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_351] at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_351] at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_351] at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_351] at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:161) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:128) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:113) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.core.PGStream.receiveChar(PGStream.java:453) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2119) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:355) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:167) ~[postgresql-42.3.8.jar:42.3.8] at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:156) ~[postgresql-42.3.8.jar:42.3.8] at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:483) ~[druid-1.2.14.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_351] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_351] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_351] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_351] at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) ~[mybatis-3.4.6.jar:3.4.6] at com.sun.proxy.$Proxy241.execute(Unknown Source) ~[na:na] at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.4.6.jar:3.4.6] at com.github.pagehelper.util.ExecutorUtil.executeAutoCount(ExecutorUtil.java:138) ~[pagehelper-5.1.7.jar:na] at com.github.pagehelper.PageInterceptor.count(PageInterceptor.java:148) ~[pagehelper-5.1.7.jar:na] at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:97) ~[pagehelper-5.1.7.jar:na] at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.4.6.jar:3.4.6] at com.sun.proxy.$Proxy239.query(Unknown Source) ~[na:na] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) ~[mybatis-3.4.6.jar:3.4.6] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_351] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_351] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_351] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_351] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ~[mybatis-spring-1.3.2.jar:1.3.2] at com.sun.proxy.$Proxy85.selectList(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230) ~[mybatis-spring-1.3.2.jar:1.3.2] at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:139) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:76) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) ~[mybatis-3.4.6.jar:3.4.6] at com.sun.proxy.$Proxy175.getLteDay(Unknown Source) ~[na:na]

zsg2023 commented 1 year ago

1、请提供详细的异常堆栈。 2、也请检查两种情况下,是否pg驱动版本不一致。 目前我们的环境也出现了问题,在普通的数据库操作没有问题。时间长一点的数据库访问,就会出现 【org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.】 【Caused by: java.net.SocketTimeoutException: Read timed out】 程序没有改动只是升级了druid-1.2.16.jar或者1.2.17.jar 请尽快看一下,很多人都出现了这个问题。 postgresql-42.6.0.jar

guochunjiang commented 1 year ago

我也出现这种问题。升级到1.2.18就出现这种问题。 SQL请求稍微耗时长一点的就返回不出来。: An I/O error occurred while sending to the backend

xxd-China commented 1 year ago

有人解决了吗

kimmking commented 1 year ago

@enchanterzj @changuoqiang @guochunjiang @xxd-China You should upgrade druid >= 1.2.15, this version fixed it by https://github.com/alibaba/druid/issues/5096

txkbc commented 4 months ago

我现在用的1.2.18,也出现了这个问题。 改为1.2.16就好了

gjhjoy commented 1 month ago

我也遇到同样的问题,druid版本1.2.16,查询时间长一点就返回read timed out,即使配置了30分钟超时时间,一到30分钟就报超时的错误,其实查询只需要1分钟

txkbc commented 1 month ago

我已收到邮件   会尽快给你回复!!!