You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "David Rees (JIRA)" <ji...@apache.org> on 2008/02/29 05:24:51 UTC

[jira] Commented: (DBCP-65) [dbcp] Deadlock when evicting dbcp objects (testWhileIdle=true)

    [ https://issues.apache.org/jira/browse/DBCP-65?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12573586#action_12573586 ] 

David Rees commented on DBCP-65:
--------------------------------

This bug still exists in 1.2.2. I don't think that removing the prepareStatement synchronization helps, there is still a lock-race between the Evictor and returning objects to the pool for example.

Here is a stack trace, I've had this happen twice in the last week on two completely different applications (after using dbcp successfully without issue for years!):

"Timer-0":
at org.apache.commons.dbcp.AbandonedTrace.addTrace(AbandonedTrace.java:175)
waiting to lock <0x0000002aa04d4be8> (a org.apache.commons.dbcp.PoolableConnection)
at org.apache.commons.dbcp.AbandonedTrace.init(AbandonedTrace.java:92)
at org.apache.commons.dbcp.AbandonedTrace.<init>(AbandonedTrace.java:82)
at org.apache.commons.dbcp.DelegatingStatement.<init>(DelegatingStatement.java:61)
at org.apache.commons.dbcp.DelegatingConnection.createStatement(DelegatingConnection.java:224)
at org.apache.commons.dbcp.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:331)
at org.apache.commons.dbcp.PoolableConnectionFactory.validateObject(PoolableConnectionFactory.java:312)
at org.apache.commons.pool.impl.GenericObjectPool.evict(GenericObjectPool.java:1217)
locked <0x0000002a9ee91bf8> (a org.apache.commons.pool.impl.GenericObjectPool)
at org.apache.commons.pool.impl.GenericObjectPool$Evictor.run(GenericObjectPool.java:1341)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
"SocketRequest-8":
at org.apache.commons.pool.impl.GenericObjectPool.addObjectToPool(GenericObjectPool.java:1137)
waiting to lock <0x0000002a9ee91bf8> (a org.apache.commons.pool.impl.GenericObjectPool)
at org.apache.commons.pool.impl.GenericObjectPool.returnObject(GenericObjectPool.java:1076)
at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:87)
locked <0x0000002aa04d4be8> (a org.apache.commons.dbcp.PoolableConnection)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
at my.package.DbUtil.close(DbUtil.java:545)

In this configuration, minIdle=0, maxIdle=4, maxActive=8, testWhileIdle=true timeBetweenEvictionRunsMillis=15000

It appears that the only workaround for now to prevent this deadlock is to disable the Evictor thread by disabling testWhileIdle.

I have two comments on DBCP-44 with other information (before I realized that this was the bug I was hitting, though they are related).

> [dbcp] Deadlock when evicting dbcp objects (testWhileIdle=true)
> ---------------------------------------------------------------
>
>                 Key: DBCP-65
>                 URL: https://issues.apache.org/jira/browse/DBCP-65
>             Project: Commons Dbcp
>          Issue Type: Bug
>         Environment: Operating System: All
> Platform: All
>            Reporter: Wang Xianzhu
>             Fix For: 1.2.2
>
>
> The GenericKeyedObjectPool$Evictor thread has probability of deadlock with dbcp
> objects.
> For example, at a certain time, a normal user thread calls a PoolingConnection
> object's synchronized method, which in turn calls GenericKeyedObjectPool
> object's synchronzied method.
> At the same time, the evictor thread calls the GenericKeyedObjectPool object's
> synchronized method 'evict', which in turn calls the PoolingConnection object's
> synchronized method.  When testWhileIdle=true, the probability of evictor
> calling GenericKeyedObjectPool's synchronized method is much greater.
> The following is the deadlock information in the thread dump of our program
> (testWhileIdle=true):
> "Thread-106":
> 	at org.apache.commons.dbcp.AbandonedTrace.removeTrace(AbandonedTrace.java:221)
> 	- waiting to lock <0x6a6b1b80> (a org.apache.commons.dbcp.PoolingConnection)
> 	at
> org.apache.commons.dbcp.PoolablePreparedStatement.passivate(PoolablePreparedStatement.java:100)
> 	at
> org.apache.commons.dbcp.PoolingConnection.passivateObject(PoolingConnection.java:239)
> 	at
> org.apache.commons.pool.impl.GenericKeyedObjectPool.evict(GenericKeyedObjectPool.java:1001)
> 	- locked <0x6a6b1858> (a org.apache.commons.pool.impl.GenericKeyedObjectPool)
> 	at
> org.apache.commons.pool.impl.GenericKeyedObjectPool$Evictor.run(GenericKeyedObjectPool.java:1156)
> 	at java.lang.Thread.run(Thread.java:534)
> "Thread-41":
> 	at
> org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:715)
> 	- waiting to lock <0x6a6b1858> (a
> org.apache.commons.pool.impl.GenericKeyedObjectPool)
> 	at
> org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:87)
> 	- locked <0x6a6b1b80> (a org.apache.commons.dbcp.PoolingConnection)
> 	at
> org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:185)
> 	at
> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:278)
> ...
> This problem can be worked around by setting testWhileIdle to false, although
> there is still very small possibility of deadlock.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.