druid连接池使用过程遇到的一个奇怪异常
2017-09-12 08:43
1621 查看
某天日志中连续都是如下的异常:2017-09-06 21:39:52.936 ERROR [DruidDataSource.java:1974] create connection holder errororg.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction blockat org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgConnection.execSQLQuery(PgConnection.java:416) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgConnection.execSQLQuery(PgConnection.java:410) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgConnection.getTransactionIsolation(PgConnection.java:793) ~[postgresql-42.1.1.jar:42.1.1]at com.alibaba.druid.filter.FilterChainImpl.connection_getTransactionIsolation(FilterChainImpl.java:362) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.filter.FilterAdapter.connection_getTransactionIsolation(FilterAdapter.java:871) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.filter.FilterChainImpl.connection_getTransactionIsolation(FilterChainImpl.java:359) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.getTransactionIsolation(ConnectionProxyImpl.java:260) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:145) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:84) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidDataSource.put(DruidDataSource.java:1964) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2221) [druid-1.1.0.jar:1.1.0]Caused by: org.postgresql.util.PSQLException: ERROR: canceling statement due to user requestat org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264) ~[postgresql-42.1.1.jar:42.1.1]at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:231) ~[postgresql-42.1.1.jar:42.1.1]at com.alibaba.druid.pool.vendor.PGValidConnectionChecker.isValidConnection(PGValidConnectionChecker.java:65) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1293) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1539) ~[druid-1.1.0.jar:1.1.0]at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2178) [druid-1.1.0.jar:1.1.0]最后查找资料,查看druid源代码,终于找到了原因,在数据库建立连接时,会检查连接状况:
(!= ) { result = ; Exception error = ; { result = .isValidConnection(conn, , ); } (Exception ex) { error = ex; } (!result) { SQLException sqlError = error != ? SQLException(, error) : SQLException(); sqlError; } ; }由于我们使用的是postgres数据库,在PGValidConnectionChecker代码中
int queryTimeout = validationQueryTimeout < 0 ? defaultQueryTimeout : validationQueryTimeout; Statement stmt = ; ResultSet rs = ; { stmt = conn.createStatement(); stmt.setQueryTimeout(queryTimeout); rs = stmt.executeQuery(validateQuery); ;此处validationQueryTime默认值-1,defaultQueryTimeout则为1,这就造成执行sql语句需要在1秒内返回,偏偏那时候我们数据库正处于非常复杂的计算中,没有及时响应,就抛出了如下异常Caused by: org.postgresql.util.PSQLException: ERROR: canceling statement due to user request,然后更有趣的事情发生了这段代码是数据源建立连接的时候,测试连接是否通顺运行的,抛出异常后,由于此处result默认为true,抛出异常也没有更改result为false,然后该连接会被正常使用,由于本身该连接使用过程中已经出现过异常,再次使用就会抛出ERROR [DruidDataSource.java:1974] create connection holder errororg.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block由于druid的连接池未满,所以不停的创建连接,接连不断抛出如上异常
相关文章推荐
- Hive的--auxpath使用相对路径遇到的一个奇怪的异常
- stvchu兄,memcacheq使用过程中遇到一个小麻烦,现在搞不定了,求助
- Cursor使用过程中遇到的一个问题
- ISE使用过程中遇到的一个诡异问题
- 在使用WINSOCK2.H头文件时遇到的一个奇怪问题
- 使用onceclick发布winform项目时遇到的一个异常
- MyEclipse调试过程中遇到一个奇怪的问题
- 使用4.3.11版本的hibernate结合druid连接池遇到的问题
- Glide使用过程中遇到timeout异常的处理方式
- ie8下使用knockoutjs遇到的一个模板异常
- VS使用过程遇到的异常及解决方法
- 使用Windows 7自带IIS(7.5)搭建FTP服务时遇到的一个奇怪问题
- 使用android studio过程中遇到的异常
- thinkphp 使用过程中遇到的一个小函数
- Asp.net forms认证遇到的一个奇怪的问题和测试过程
- 使用SSRS设计报表布局时遇到的一个奇怪问题
- python使用过程中遇到的各种奇怪的问题
- 使用RabbitMQ过程中遇到的一个问题(队列为空,但内存暴涨)以及与开发者的邮件沟通
- 记一个奇怪的python异常处理过程
- Chrome 下,重复使用 XMLHttpRequest进行Post数据时,遇到一个奇怪的问题