We're updating the issue view to help you get more done. 

RuntimeException during releaseStatements causes JDBC connection not to be closed

Description

We have seen exceptions in production related to some misconfiguration of our Infinispan / JGroups clustering. Another story. What happened was an SQLException is thrown when Hibernate tried to release a ResultSet, this resulted in a RuntimeException (as the SQLException is rethrown as an UndeclaredThrowableException) and misses the connection.close() which leaves hanging connections and eventually connection starvation.

What do you think about putting the connection.close() in JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:190) into a finally block?

Here is the exception stacktrace that we are seeing that is causing this issue:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 java.lang.reflect.UndeclaredThrowableException at com.sun.proxy.$Proxy39.hashCode(Unknown Source) at java.util.HashMap.hash(HashMap.java:338) at java.util.HashMap.get(HashMap.java:556) at org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl.release(ResourceRegistryStandardImpl.java:76) at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.releaseStatements(AbstractBatchImpl.java:157) at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.release(AbstractBatchImpl.java:195) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:190) at org.hibernate.internal.SessionImpl.close(SessionImpl.java:424) at com.xk72.hibernate.session.internal.AbstractHibernateSessionInvocationHandler.doClose(AbstractHibernateSessionInvocationHandler.java:230) at com.xk72.hibernate.session.internal.AbstractHibernateSessionInvocationHandler.actuallyClose(AbstractHibernateSessionInvocationHandler.java:218) at com.xk72.hibernate.session.internal.AbstractHibernateSessionInvocationHandler.invoke(AbstractHibernateSessionInvocationHandler.java:72) at com.sun.proxy.$Proxy66.actuallyClose(Unknown Source) at com.xk72.hibernate.session.internal.HibernateCurrentSessionProvider.completelyCloseCurrentSession(HibernateCurrentSessionProvider.java:157) at com.xk72.hibernate.session.internal.StandardHibernateSessionProvider.completelyCloseCurrentSession(StandardHibernateSessionProvider.java:82) at com.cactuslab.supermodel.utils.HibernateUtil.completelyCloseCurrentSession(HibernateUtil.java:65) at com.cactuslab.supermodel.web.SupermodelRootActionContext.doRootAction(SupermodelRootActionContext.java:152) at com.xk72.webparts.actions.ActionFilter.doFilter(ActionFilter.java:143) at com.xk72.webparts.actions.ActionFilter.doFilter(ActionFilter.java:69) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.cactuslab.supermodel.web.SupermodelFilter.doFilter(SupermodelFilter.java:58) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.xk72.webparts.csrf.CSRFFilter.doFilter(CSRFFilter.java:93) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.xk72.webparts.multipart.MultipartHttpFilter.doFilter(MultipartHttpFilter.java:31) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.xk72.webparts.RequestCharacterEncodingFilter.doFilter(RequestCharacterEncodingFilter.java:30) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:190) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.sql.SQLException: Statement closed. at org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor$StatementProxy.invoke(StatementDecoratorInterceptor.java:238) ... 47 more

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Karl von Randow

Components

Fix versions

Affects versions

5.1.0

Priority

Minor