commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From harald-nos...@gmxpro.de
Subject [DBCP] SharedPoolDataSource don't remove connection object from pool if an error occured
Date Tue, 30 May 2006 13:30:42 GMT
Hi,

I have a problem with DBCP and SharedPoolDataSource. 

If the connection broken (such as I kill the connection on the datebase) 
then the the connection don't remove from the pool. 

Therefore I look into the source code from dbcp.

If a error occured then the event listener call destroyObject method.
( connectionErrorOccurred or connectionClosed in KeyedCPDSConnectionFactory).

The method destroyObject from KeyedCPDSConnectionFactory close the connection but don't remove
it from the pool. Without a testOnBorrow|testOnReturn|testWhileIdle() the connection 
don't remove from the pool never.

Therefor I propose to replace the call 
	destroyObject(info.getUserPassKey(), info) 
with
        _pool.invalidateObject(info.getUserPassKey(), info);
in connectionErrorOccurred and connectionClosed from KeyedCPDSConnectionFactory.

Proposed patch:
--- ./src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java.orig
+++ ./src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java

@@ -137,6 +137,7 @@
     public void destroyObject(Object key, Object obj) throws Exception {
         if (obj instanceof PooledConnectionAndInfo) {
             PooledConnection pc = ((PooledConnectionAndInfo)obj).getPooledConnection();
+            pc.removeConnectionEventListener(this);
             pcMap.remove(pc);
             pc.close();
         }
@@ -226,8 +227,9 @@
             } catch (Exception e) {
                 System.err.println("CLOSING DOWN CONNECTION AS IT COULD " +
                                    "NOT BE RETURNED TO THE POOL");
+                pc.removeConnectionEventListener(this);
                 try {
-                    destroyObject(info.getUserPassKey(), info);
+                    _pool.invalidateObject(info.getUserPassKey(), info);
                 } catch (Exception e2) {
                     System.err.println("EXCEPTION WHILE DESTROYING OBJECT " +
                                        info);
@@ -253,7 +255,8 @@
             //interested in errors since we are about to close this connection
             pc.removeConnectionEventListener(this);
         } catch (Exception ignore) {
-            // ignore
+          System.err.println("EXCEPTION WHILE REMOVING LISTENER OF OBJECT " + ignore);
+          ignore.printStackTrace();
         }

         PooledConnectionAndInfo info = (PooledConnectionAndInfo) pcMap.get(pc);
@@ -261,7 +264,7 @@
             throw new IllegalStateException(NO_KEY_MESSAGE);
         }
         try {
-            destroyObject(info.getUserPassKey(), info);
+            _pool.invalidateObject(info.getUserPassKey(), info);
         } catch (Exception e) {
             System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
             e.printStackTrace();

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


Mime
View raw message