Issue Details (XML | Word | Printable)

Key: POOL-146
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: bhupesh bansal
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Pool

Thread deadlock issue in GenericKeyedObjectPool borrowObject()

Created: 29/Jun/09 11:32 PM   Updated: 14/Jul/09 01:13 AM
Return to search
Component/s: None
Affects Version/s: 1.5, 1.5.1
Fix Version/s: 1.5.2

Time Tracking:
Not Specified

Resolution Date: 05/Jul/09 06:16 PM


 Description  « Hide
I am a new user of common-pools and I was having some weird behavior with GenericKeyedObjectPool

GenericKeyedObjectPool: 1074:1077

public Object borrowObject(Object key) throws Exception {
long starttime = System.currentTimeMillis();
Latch latch = new Latch(key); ---> This object is tried to be used for managing pool size by calling wait()/notify()

My thinking is this should be a shared/global object and not created new for each call ??



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Phil Steitz added a comment - 29/Jun/09 11:46 PM
Can you be more specific on the "weird behavior" you are observing?

bhupesh bansal added a comment - 30/Jun/09 12:07 AM
sure,

I am using it as a Socket pool with the KeyedPoolableObjectFactory as a socketFactory which returns a socket for each makeObject() call
and close the socket in destroyObject()

The Test scenario which causes issue is this:
Client --> socket call to server A and B (B is slow in freeing up resource where A is fast to free)

Common-Pools-1.5.1 : both A and B start throwing NoSuchElementException
Common-Pools-1.4 : only A throws NoSuchElementException and B keeps allocating resource.

I am trying to write a test case for the same will attach it once m done.

Best
Bhupesh


bhupesh bansal added a comment - 30/Jun/09 12:08 AM
Correction : A is slow in freeing up resource where B is fast (not vice-versa as mentioned last time)

Mark Thomas added a comment - 02/Jul/09 12:53 PM
Am I correct in thinking that your have a single pool of sockets that clients use to connect to either Server A or Server B?

bhupesh bansal added a comment - 03/Jul/09 07:46 PM
Yes...

they share the same socket pool (GenericKeyedObjectPool) keyed on nodeId for server A /B.

my understanding is threads blocked on Key A (slow server) should not cause thread blocking for Key B ?? Is this assumption correct.


Mark Thomas added a comment - 05/Jul/09 05:06 PM
OK, now I understand.

That is a bug although making the Latch object global is not the way to address this. I have added a test case and am working on a patch.


Mark Thomas added a comment - 05/Jul/09 06:16 PM
This has now been fixed. Many thanks for the report.

bhupesh bansal added a comment - 05/Jul/09 09:15 PM
Many Thanks Mark,

Can you attach the patch to this bug ?? I would like to see the fix I spent considerable time looking into the commons-pools code base and couldn't find the issue and yes global Latch was not a solution I understood after looking into the code later.

BTW have you looked into ArrayBlockingQueue from java 1.5.0 onwards in their concurrent package ?? I was thinking using that would clean up the code a lot ?


Mark Thomas added a comment - 05/Jul/09 09:31 PM
Use the "Subversion commits" tab to see the changes related to this bug.

Utilising JDK 1.5 features is one of the considerations for the Pool 2.x series. There was a thread on the commons dev list about this not that long ago.


Paul Lindner added a comment - 06/Jul/09 04:37 AM
Regarding ArrayBlockingQueue there is always backport-util-concurrent, seems like a logical step to me if 1.4 compatibility is desired..