db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r612262 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/SectionManager.java testing/org/apache/derbyTesting/functionTests/master/derbyStress.out testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
Date Tue, 15 Jan 2008 22:36:40 GMT
Author: kmarsden
Date: Tue Jan 15 14:36:38 2008
New Revision: 612262

URL: http://svn.apache.org/viewvc?rev=612262&view=rev
Log:
DERBY-3316  Leak in client if ResultSet not closed

The leak was in SectionManager.positionedUpdateCursorNameToResultSet_ which kept a reference
to the ResultSet so it wouldn't get garbage collected. The solution was to use a WeakReference
to the ResultSets in positionedUpdateCursorNameToResultSet_ so that they can be garbage collected.


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derbyStress.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java?rev=612262&r1=612261&r2=612262&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java Tue Jan
15 14:36:38 2008
@@ -21,6 +21,8 @@
 
 package org.apache.derby.client.am;
 
+import java.lang.ref.WeakReference;
+
 import org.apache.derby.shared.common.reference.JDBC30Translation;
 
 import org.apache.derby.shared.common.reference.SQLState;
@@ -184,11 +186,12 @@
     }
 
     void mapCursorNameToResultSet(String cursorName, ResultSet resultSet) {
-        positionedUpdateCursorNameToResultSet_.put(cursorName, resultSet);
+        // DERBY-3316. Needs WeakReference so that ResultSet can be garbage collected
+        positionedUpdateCursorNameToResultSet_.put(cursorName, new WeakReference(resultSet));
     }
 
     ResultSet getPositionedUpdateResultSet(String cursorName) throws SqlException {
-        ResultSet rs = (ResultSet) positionedUpdateCursorNameToResultSet_.get(cursorName);
+        ResultSet rs = (ResultSet) ((WeakReference) (positionedUpdateCursorNameToResultSet_.get(cursorName))).get();
         if (rs == null) {
             throw new SqlException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.CLIENT_RESULT_SET_NOT_OPEN));

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derbyStress.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derbyStress.out?rev=612262&r1=612261&r2=612262&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derbyStress.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derbyStress.out
Tue Jan 15 14:36:38 2008
@@ -2,4 +2,5 @@
 Testing with 2000 prepared statements
 PASS -- Prepared statement test
 DERBY-557: reExecuteStatementTest() PASSED
-Test derbyStress finished.
\ No newline at end of file
+DERBY-3316: Multiple statement executions 
+Test derbyStress finished.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java?rev=612262&r1=612261&r2=612262&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
Tue Jan 15 14:36:38 2008
@@ -54,7 +54,7 @@
 			}
 
 			reExecuteStatementTest();
-
+			testDerby3316();
 			System.out.println("Test derbyStress finished.");
 		} catch (SQLException se) {
 			TestUtil.dumpSQLExceptions(se);
@@ -133,4 +133,37 @@
 		conn.close();
 		System.out.println("PASSED");
 	}
+        
+    /**
+     * Test fix for leak if ResultSets are not closed.
+     * @throws Exception
+     */
+    public static void testDerby3316() throws Exception {
+          System.out.println("DERBY-3316: Multiple statement executions ");
+          Connection conn = ij.startJBMS();
+                
+          Statement s = conn.createStatement();
+          s.executeUpdate("CREATE TABLE TAB (col1 varchar(32672))");
+          PreparedStatement ps = conn.prepareStatement("INSERT INTO TAB VALUES(?)");
+          ps.setString(1,"hello");
+          ps.executeUpdate();
+          ps.setString(1,"hello");
+          ps.executeUpdate();
+          ps.close();
+          for (int i = 0; i < 2000; i++)
+          {
+                  s = conn.createStatement();
+                  ResultSet rs = s.executeQuery("SELECT * from tab");
+                  // drain the resultset
+                  while (rs.next());
+                  // With DERBY-3316, If I don't explicitly close the resultset or 
+                  // statement, we get a leak.
+                  //rs.close();
+                  //s.close();
+          }    
+          s = conn.createStatement();
+          s.executeUpdate("DROP TABLE TAB");
+          s.close();
+       }
+      
 }



Mime
View raw message