commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <phil.ste...@gmail.com>
Subject Re: Re: [dbcp] Error when closing a connection (maybe DBCP-216?)
Date Tue, 20 Nov 2007 06:39:20 GMT
On Nov 13, 2007 2:44 AM,  <stephane.demurget@bnpparibas.com> wrote:
> hi again,
>
> thanks for the answer. I looked at the random connection closed exceptions
> but I'm correctly closing my connections. I've attached a stacktrace that
> happen later, sorry, it was of course less obvious to figure out like
> that... Here is the first exception I have:
>
> Thread [pool-5-thread-4] (Suspended (exception IllegalStateException))
>         KeyedCPDSConnectionFactory.connectionClosed(ConnectionEvent) line:
> 265
>         SybPooledConnection.notifyListeners(SQLException) line: 225
>         SybConnectionProxy.close() line: 106
>         SybPooledConnection.close() line: 166
>         KeyedCPDSConnectionFactory.destroyObject(Object, Object) line: 175
>
>         GenericKeyedObjectPool.returnObject(Object, Object) line: 997
>         KeyedCPDSConnectionFactory.connectionClosed(ConnectionEvent) line:
> 268
>         SybPooledConnection.notifyListeners(SQLException) line: 225
>         SybConnectionProxy.close() line: 106
>         ... (i'm calling close on the SQL Connection here, when the thread
> is finished)
>
> After analyzing it a bit I understand the pool wants to destroy the object
> because my pool can not support any more idle connection (I'm at the point
> where active=maxActive=maxIdle=5).
> What I do not understand is why the destroyObject method does:
>
> public void destroyObject(Object key, Object obj) throws Exception {
>         if (obj instanceof PooledConnectionAndInfo) {
>             PooledConnection pc =
> ((PooledConnectionAndInfo)obj).getPooledConnection();
>             pcMap.remove(pc);
>             pc.close();
>         }
>     }
>
> Which means it removes the mapping and close the PooledConnection. At this
> point, the listener is still active and it calls the listener which will
> obviously fail:
>
> public void connectionClosed(ConnectionEvent event) {
>         PooledConnection pc = (PooledConnection)event.getSource();
>         // if this event occured becase we were validating, ignore it
>         // otherwise return the connection to the pool.
>         if (!validatingMap.containsKey(pc)) {
>             PooledConnectionAndInfo info =
>                 (PooledConnectionAndInfo) pcMap.get(pc);
>             if (info == null) {
>                 throw new IllegalStateException(NO_KEY_MESSAGE);   //
> <--------- the Exception which is thrown
>             }
> ...
>
> Isn't this http://issues.apache.org/jira/browse/DBCP-216? Or maybe the
> driver should not notify for both the Connection and PooledConnection
> close?
> Do you have any solution?

Looks to me like this is in fact a bug in KeyedCPDSConnectionFactory,
related to DBCP-216.  Odd that this is the first report, since this
code has not been changed since the line to remove the destroyed
connection from the pc map was introduced to close a memory leak in
2004.  The only workaround that I can suggest for now is not to limit
maxIdle or try to handle the exception.

Test cases and fix are in progress.  Patches including test cases
against DBCP-216 are welcome!  There are test drivers and CPDS
adapters available to use in developing these.

Thanks for reporting this.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message