#68 InterruptedException causing connection leaks

open
nobody
None
5
2008-07-16
2008-07-16
Anonymous
No

I am using C3P0 with Hibernate over MySQL database with a limit of 5 connections.

I generated a simple test where I run multiple threads (20 for example) that constantly query the DB.

Another thread is constantly interrupting these threads, and therefore interrupting hibernate.

After some time, I get these exceptions:

org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at com.aginova.tests.HibernateTests$MyThread.run(HibernateTests.java:72)
Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:531)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
... 5 more
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1315)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 8 more

In that case, I cannot do any query to DB anymore, because all the pooled connections would return the same error.

My understanding of what happens is that when you have multiple threads connecting, some of the C3P0 queries will be in waiting mode (waiting for a connection to be available). If there is an interrupt() at that stage, the connection wait will be interrupted. It seems like C3P0 propagates this interruptedexception and that causes the connection to be (and remain) invalid. Therefore if you use a pool of 5 connections, 1 of them will become invalid. Do this step multiple times, and the whole pool becomes invalid, therefore preventing new DB queries. This happens for a web application running for a long time, using interrupt() to interrupt threads sometimes using Hibernate.

Submited by Reshad Moussa (kblack at geocities-dotcom)

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks