druid-0.2.26报Could not open JDBC Connection for transaction; nested exception is

fanwsp 发布于 2015/04/13 17:20
阅读 16K+
收藏 0

@wenshao 你好,想跟你请教个问题:

生产环境报以下错误:

Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 50

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 50

at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)

at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)

at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)

at $Proxy196.getIPCity(Unknown Source)

at cn.richinfo.cmail.webmail.web.util.LoginNotifyImpl.getCity(LoginNotifyImpl.java:214)

at cn.richinfo.cmail.webmail.web.util.LoginNotifyImpl.sendLoginNotify(LoginNotifyImpl.java:239)

at cn.richinfo.cmail.webmail.web.controller.login.common.LoginCommon.doLoginResult(LoginCommon.java:338)

at cn.richinfo.cmail.webmail.web.controller.login.common.LoginCommon.doLoginMail(LoginCommon.java:212)

at cn.richinfo.cmail.webmail.web.controller.login.SMAPSSOController.handleRequestInternal(SMAPSSOController.java:122)

at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)

at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

at cn.richinfo.cmail.webmail.web.WebmailCharacterEncodingFilter.doFilterInternal(WebmailCharacterEncodingFilter.java:39)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:891)

at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:750)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2282)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:662)

Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 50

at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1069)

at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:898)

at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4534)

at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)

at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4530)

--

--

at $Proxy56.getWebUserConfigModelById(Unknown Source)

at cn.richinfo.cmail.basemail.common.authenticate.LoginCmail.setAttrsConfig(LoginCmail.java:421)

at cn.richinfo.cmail.basemail.common.authenticate.LoginCmail.updateCmailUserInfo(LoginCmail.java:371)

at cn.richinfo.cmail.basemail.common.authenticate.AuthenticateHelper.createUserInfo(AuthenticateHelper.java:468)

at cn.richinfo.cmail.basemail.common.authenticate.AuthenticateHelper.login(AuthenticateHelper.java:285)

at cn.richinfo.cmail.webmail.web.controller.login.common.LoginCommon.doLoginMail(LoginCommon.java:210)

at cn.richinfo.cmail.webmail.web.controller.login.SMAPSSOController.handleRequestInternal(SMAPSSOController.java:122)

at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)

at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

at cn.richinfo.cmail.webmail.web.WebmailCharacterEncodingFilter.doFilterInternal(WebmailCharacterEncodingFilter.java:39)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:891)

at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:750)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2282)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:662)

Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 50

at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1069)

at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:898)

at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4534)

at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)

at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4530)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)

at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)

at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)

... 43 more


#初始化连接数
db.initialSize=5


#最大连接数量,这个开始是50个,后台故障得不到解决,临时搞100,但问题依旧
db.maxActive=100


#最大空闲连接
db.maxIdle=20


#最小空闲连接
db.minIdle=3


#是否自动回收超时连接
db.removeAbandoned=true


#超时等待时间以毫秒为单位 
db.maxWait=60000
#超时时间(以秒数为单位) defautl:300s
db.removeAbandonedTimeout=180
#连接池中连接,在时间段内一直空闲, 被逐出连接池的时间(默认为30分钟,可以适当做调整,需要和后端服务端的策略配置相关) -->
db.minEvictableIdleTimeMillis=180000
#设置的Evict线程的时间,单位ms,大于0才会开启evict检查线程
db.timeBetweenEvictionRunsMillis=30000

以下是数据源的配置:

<!-- 配置数据源 -->

<bean id="ds_cmail_web" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">

        <property name="driverClassName"><value>${db.web.driverClassName}</value></property>

        <property name="url"><value>${db.web.url}</value></property>

        <property name="username"><value>${db.web.username}</value></property>

        <property name="password"><value>${db.web.password}</value></property>

        <property name="filters" value="stat" />  

        <property name="maxActive"><value>${db.maxActive}</value></property>  

        <property name="initialSize"><value>${db.initialSize}</value></property>  

        <property name="maxWait"><value>${db.maxWait}</value></property>  

        <property name="minIdle"><value>${db.minIdle}</value></property>  

        <property name="timeBetweenEvictionRunsMillis"><value>${db.timeBetweenEvictionRunsMillis}</value></property>  

        <property name="minEvictableIdleTimeMillis"><value>${db.minEvictableIdleTimeMillis}</value></property> 

        <property name="maxOpenPreparedStatements"><value>${db.maxOpenPreparedStatements}</value></property> 

        <property name="removeAbandonedTimeout"><value>${db.removeAbandonedTimeout}</value></property> 

        <property name="validationQuery" value="SELECT 'x'" />  

        <property name="testWhileIdle" value="true" />  

        <property name="testOnBorrow" value="false" />  

        <property name="testOnReturn" value="false" />  

        <property name="removeAbandoned" value="true" /> <!-- 打开removeAbandoned功能 -->  

        <property name="logAbandoned" value="true" /> <!-- 关闭abanded连接时输出错误日志 -->

</bean>


1. 环境是spring+mybatis, 使用Druid-0.2.26版本做为数据连接池

2. 数据库是做的主-从备份(故障发生时,重启数据库,问题依旧)

3. 故障发生时,重启应用的tomcat,问题还是存在。(很难理解应用重启故障还是存在)


发生故障之前的代码运行了4-5天,没有出现问题。突然今天出现,在各种方法尝试没有解决后,把程序回滚到上个版本(数据库操作这一块代码没有变,新版只是增加了几个数据库的操作而已),后台程序正常。  然后局部机器更新到新的程序,问题没有发生。

不知道此故障是否和druid数据源连接有关,或者可能发生的原因,望指教!


以下是问题补充:

@fanwsp:系统还发现这种错误日志: 2015-04-13 10:31:20,735 [WARN] com.alibaba.druid.pool.DruidDataSource - get/close not same thread 2769 2015-04-13 10:31:20,755 [ERROR] com.alibaba.druid.pool.DruidDataSource - abandon connection, open stackTrace 2770 at java.lang.Thread.getStackTrace(Thread.java:1479) 2771 at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:942) 2772 at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4534) 2773 at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661) 2774 at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4530) 2775 at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880) 2776 at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872) 2777 at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97) 2778 at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202) 2779 at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) 2780 at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335) 2781 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105) 2782 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2783 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 2784 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2785 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) 2786 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2787 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 2788 at $Proxy196.getIPCity(Unknown Source) (2015/04/13 18:14)
@fanwsp: 2438 org.springframework.transaction.TransactionSystemException: Could not commit JDBC transaction; nested exception is java.sql.SQLException: connection holder is null 2439 at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:270) 2440 at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) 2441 at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) 2442 at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) 2443 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) 2444 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2445 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 2446 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2447 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 2448 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2449 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 2450 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2451 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) 2452 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 2453 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 2454 at $Proxy196.getIPCity(Unknown Source) 2455 at cn.richinfo.cmail.webmail.web.util.LoginNotifyImpl.getCity(LoginNotifyImpl.java:214) 继续发现上面的日志。 cn.richinfo.cmail.webmail.web.util.LoginNotifyImpl.getCity(LoginNotifyImpl.java:214) 显示这一行业务调用代码出错,但系统其它所有操作数据的地方都出现过获取连接超时的问题 (2015/04/13 20:28)
@fanwsp:2015-04-13 11:10:15,991 [ERROR] com.alibaba.druid.pool.DruidDataSource - discard connection 201513 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown. 201514 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 201515 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 201516 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 201517 at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 201518 at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 201519 at com.mysql.jdbc.Util.getInstance(Util.java:386) 201520 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013) 201521 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) 201522 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) 201523 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) 201524 at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1664) 201525 at com.alibaba.druid.filter.FilterChainImpl.connection_commit(FilterChainImpl.java:178) 201526 at com.alibaba.druid.filter.stat.StatFilter.connection_commit(StatFilter.java:260) 201527 at com.alibaba.druid.filter.FilterChainImpl.connection_commit(FilterChainImpl.java:174) 201528 at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.commit(ConnectionProxyImpl.java:123) 201529 at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:711) 201530 at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:267) 201531 at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) 201532 at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) 201533 at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) 201534 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) 201535 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 201536 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 201537 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 201538 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 201539 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 201540 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 还发现上面这种错误日志。 (2015/04/13 20:44)
加载中
0
wenshao
wenshao
连接不够用了
0
全班的希望

请问这个问题解决了么,我这边也遇到同样的问题了

返回顶部
顶部