commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Axel Großmann (JIRA) <j...@apache.org>
Subject [jira] Commented: (POOL-179) GenericObjectPool.borrowObject() incorrectly swallos InterruptedException
Date Tue, 04 Jan 2011 10:34:45 GMT

    [ https://issues.apache.org/jira/browse/POOL-179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12977215#action_12977215
] 

Axel Großmann commented on POOL-179:
------------------------------------

I think the important bit is that a {{InterruptedException}} must never be swallowed but passed
on to the calling code. And when the pool is doing so of course any allocated element must
be put back into the pool. 

The code that did not work with 1.5.5 looks somewhat like this:
{code:java}
try
{
   while( !Thread.currentThread.isInterrupted())
   {
      element = pool.borrowObject();
      ...
    }
}
catch( InterruptedException e)
{
   // ok, someone wants me to stop
}
{code}

If {{borrowObject()}} would swallow the exception my thread would never notice that it has
been interrupted and therefore would wrongly continue to work forever. Note that the sample
is probably overdoing things a bit since it catches {{InterruptedException}} and checks whether
the current thread is being interrupted, but the general idea should be clear. 

> GenericObjectPool.borrowObject() incorrectly swallos InterruptedException
> -------------------------------------------------------------------------
>
>                 Key: POOL-179
>                 URL: https://issues.apache.org/jira/browse/POOL-179
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 1.5.5
>         Environment: mac osx 10.5.8 jdk 1.6.0_22
>            Reporter: Axel Großmann
>         Attachments: FileDiff154-155.jpg
>
>
> I just updated from commpons-pool 1.5.4 to 1.5.5 and suddenly some of my tests crash
with threads hanging.
> After some inspection is appears that GenericObjectPool.borrowObject() no longer handles
InterruptedException correctly. I made a file diff and found that there has been a modification
in that area that contains the bug. See attached image.
> I have created a patched version absed on 1.5.4 source which works correctly in my use
case. The important part is:
> {code:java}
> catch (final InterruptedException e)
> {
>    synchronized (this)
>    {
>       if (latch.getPair() == null)
>       {
>          _allocationQueue.remove(latch);
>       }
>       else
>       {
>          _numInternalProcessing--;
>          _numActive++;
>          _allocationQueue.remove(latch);
>          returnObject(latch.getPair().value);
>       }
>    }
>    Thread.currentThread().interrupt();
>    throw e;
> }
> {code} 

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


Mime
View raw message