You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Atsushi Nakagawa (JIRA)" <ji...@apache.org> on 2016/04/11 06:08:25 UTC

[jira] [Updated] (DBCP-459) InterruptedException consumed and not reset by PoolingDataSource.getConnection()

     [ https://issues.apache.org/jira/browse/DBCP-459?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Atsushi Nakagawa updated DBCP-459:
----------------------------------
    Description: 
If while {{PoolingDataSource.getConnection()}} is waiting for an available connection, {{Thread.interrupt()}} is called against the current thread, an {{java.lang.InterruptedException}} is caught internally but not reset.

It is however thrown out wrapped in an {{java.sql.SQLException}}.

A stack trace of such an occurrence is as follows:

{noformat}
java.sql.SQLException: Cannot get a connection, general error
	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146)
	at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533)
Caused by: java.lang.InterruptedException
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1220)
	at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
	at org.apache.commons.pool2.impl.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:624)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:444)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134)
	... 8 more
{noformat}

Since the interrupt status flag is not reset, it is left to the caller to look out for it and perform the interrupt specific logic, or reset the flag.  i.e.

{code:java}
try {
    ds.getConnection()
} catch (SQLException e) {
    if (e.getCause() instanceof InterruptedException) {
        Thread.current.interrupted();
    }
}
{code}


  was:
If while {{PoolingDataSource.getConnection()}} is waiting for an available connection, {{Thread.interrupt()}} is called against the current thread, an {{java.lang.InterruptedException}} is caught internally but not reset.

It is however thrown out wrapped in an {{java.sql.SQLException}}.

A stack trace of such an occurrence is as follows:

{noformat}
java.sql.SQLException: Cannot get a connection, general error
	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146)
	at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533)
Caused by: java.lang.InterruptedException
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1220)
	at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
	at org.apache.commons.pool2.impl.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:624)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:444)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134)
	... 8 more
{noformat}

Since the interrupt status flag is not reset, it is then left to the caller to look out for it and perform the interrupt specific logic, or reset the flag.  i.e.

{code:java}
try {
    ds.getConnection()
} catch (SQLException e) {
    if (e.getCause() instanceof InterruptedException) {
        Thread.current.interrupted();
    }
}
{code}



> InterruptedException consumed and not reset by PoolingDataSource.getConnection()
> --------------------------------------------------------------------------------
>
>                 Key: DBCP-459
>                 URL: https://issues.apache.org/jira/browse/DBCP-459
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 2.1.1
>            Reporter: Atsushi Nakagawa
>            Priority: Minor
>
> If while {{PoolingDataSource.getConnection()}} is waiting for an available connection, {{Thread.interrupt()}} is called against the current thread, an {{java.lang.InterruptedException}} is caught internally but not reset.
> It is however thrown out wrapped in an {{java.sql.SQLException}}.
> A stack trace of such an occurrence is as follows:
> {noformat}
> java.sql.SQLException: Cannot get a connection, general error
> 	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146)
> 	at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533)
> Caused by: java.lang.InterruptedException
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1220)
> 	at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
> 	at org.apache.commons.pool2.impl.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:624)
> 	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:444)
> 	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
> 	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134)
> 	... 8 more
> {noformat}
> Since the interrupt status flag is not reset, it is left to the caller to look out for it and perform the interrupt specific logic, or reset the flag.  i.e.
> {code:java}
> try {
>     ds.getConnection()
> } catch (SQLException e) {
>     if (e.getCause() instanceof InterruptedException) {
>         Thread.current.interrupted();
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)