Issue Details (XML | Word | Printable)

Key: POOL-102
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: John Sumsion
Votes: 1
Watchers: 2
Operations

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

Thread waiting forever for borrowObject() cannot be interrupted

Created: 30/May/07 06:23 PM   Updated: 18/Jul/08 03:50 AM
Return to search
Component/s: None
Affects Version/s: 1.1, 1.2, 1.3
Fix Version/s: 2.0

Time Tracking:
Not Specified

Resolution Date: 22/Jun/07 06:13 AM


 Description  « Hide
In the following GenericObjectPool snippet inside borrowObject(), InterruptedException is caught and ignored.

case WHEN_EXHAUSTED_BLOCK:
try {
if(_maxWait <= 0) { wait(); } else { wait(_maxWait); }
} catch(InterruptedException e) { // ignored }

There are two problems here:
1) a thread waiting forever to get an object out of the pool will NEVER terminate, even if interrupted
2) even if you put a "throw e" in, it will still be wrong because the thread's interrupted status is not preserved

This will cause cancellation problems for threads that are inside borrowObject() that want to terminate early ONLY if they are interrupted.

For example, if a borrow-and-wait-forever was running on an pooled executor thread in Java 1.5 and the executor service tried to cancel a task and that task had early-termination logic in it that checked interrupted status to terminate early, the task would never be cancelled.

For us, this is minor because we are on a Tomcat request thread that has to wait for this resource to continue, but for others that have pools of stuff that are being used by time-bound tasks, it's inconvenient to write code that waits for what ends up being arbitrary time periods for a wait. It would be easier to just say wait forever and allow interruption by someone else who is watching me.

Suggestion: make the code read like this:

case WHEN_EXHAUSTED_BLOCK:
try {
if(_maxWait <= 0) { wait(); } } else { wait(_maxWait); }
} catch(InterruptedException e) { Thread.currentThread().interrupt(); throw e; }



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Phil Steitz added a comment - 22/Jun/07 06:13 AM
Patch applied. Thanks!

jochen added a comment - 18/Jul/08 03:50 AM
Steitz,

It seems the Revision #549729 doesn't work. we met the issue on the HTTP threads being response to concurrent 40 users, which made the connection pool was exhausted and all of HTTP threads waiting on GenericObjectPool.borrowObject happened.

Given the commons pool v2.0 doesn't come out, I got the v1.4 and was pleased to see the bug fixes list - Allowed blocked threads in GenericObjectPool borrowObject to be interrupted. Issue: POOL-102. But unfortunately it didn't fix our issue when I replaced the v1.4 with v1.3. HTTP threads were still waiting for GenericObjectPool.borrowObject.

is it any solution to solve it out or any workaround exists? many thanks.