You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org> on 2005/09/08 17:33:39 UTC

[jira] Created: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
-----------------------------------------------------------------------------------------

         Key: DERBY-557
         URL: http://issues.apache.org/jira/browse/DERBY-557
     Project: Derby
        Type: Bug
  Components: Network Client  
    Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0    
    Reporter: Knut Anders Hatlen
    Priority: Minor
     Fix For: 10.1.2.0, 10.2.0.0


When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.

Example:

	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
	while (true) {
		ResultSet rs = ps.executeQuery();
	}

This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:

  For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
     - all of the rows have been retrieved
     - the associated Statement object is re-executed
     - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Kathey Marsden (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12329543 ] 

Kathey Marsden commented on DERBY-557:
--------------------------------------

Thanks Knut for the patch.
It looks good and I committed it to the trunk.  

Date: Fri Sep 16 06:52:14 2005
New Revision: 289539

URL: http://svn.apache.org/viewcvs?rev=289539&view=rev


A couple of questions though.

1) What do you think about adding a test.?  The heap can be set  using jvmflags  in an app_properties  file as we do in tests/largedata

2) Do you want this to go into the 10.1.2 release?  If so, you can just merge and test in your workspace and then post the svn merge command here and I'll port it to the branch. I think it would be a great to address some of these memory issues for 10.1.2.




> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]

Knut Anders Hatlen updated DERBY-557:
-------------------------------------

    Attachment: DERBY-557-regression-test.diff
                DERBY-557-regression-test.stat

Added a test case for DERBY-557 to jdbcapi/derbyStress.java. I have
verified that the test case fails without the fix.

I had to enable the test for DerbyNetClient. Since the test case for
DERBY-210 currently fails under DerbyNetClient, I disabled that test
case in the java code by adding this to prepStmtTest():

  // Don't run under DerbyNetClient until DERBY-210 is fixed
  if (TestUtil.isDerbyNetClientFramework()) return;

Derbyall ran cleanly.

Could someone please review?

Thanks.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557-regression-test.diff, DERBY-557-regression-test.stat, DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12322938 ] 

Knut Anders Hatlen commented on DERBY-557:
------------------------------------------

Quoting myself from derby-user:

> FYI, I had a look in the client driver code. It seems like only
> markClosed() is called on the open ResultSets when a statement is
> re-executed. The difference between close() and markClosed() is
> basically that close() additionally checks whether it should
> auto-commit, nulls out the cursor and meta data, and calls
>
>   connection_.CommitAndRollbackListeners_.remove(this);
>
> Could this be our memory leak? Is there any situation where one
> shouldn't call close() on the result sets when re-executing?

After I sent this mail, I ran a test with some println-statements in the client driver. When the OutOfMemoryError was thrown the CommitAndRollbackListeners_ list had around 17000 elements when using Statement, and around 300000 elements when using PreparedStatement.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0

>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Reopened: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]
     
Knut Anders Hatlen reopened DERBY-557:
--------------------------------------


Reopening to add regression test.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12331467 ] 

Knut Anders Hatlen commented on DERBY-557:
------------------------------------------

Kathey, I think you should just go ahead and port the fix to 10.1.

Merge command:

  svn merge -r 289538:289539 https://svn.apache.org/repos/asf/db/derby/code/trunk

I have started working on a general check-that-resources-are-freed
test for DERBY-23, DERBY-210 and DERBY-557, but while doing that I ran
into another resource leak (DERBY-594) that I wanted to resolve first.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Kathey Marsden (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12331441 ] 

Kathey Marsden commented on DERBY-557:
--------------------------------------

Should I go ahead and port this to 10.1 or wait for the test?

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12329549 ] 

Knut Anders Hatlen commented on DERBY-557:
------------------------------------------

Kathey,

Thanks for committing. Answers to your questions follow.

1) I could write a test like "run this loop for x minutes and see if an OutOfMemoryError is thrown". With a small heap it would run out of memory fairly soon. Is this the kind of test you want? Where does such a test belong? derbylang? derby*mats?

2) I merged the changes and tested with 10.1 earlier today. Didn't get OutOfMemoryError and derbyall ran successfully (except some encryption tests, as usual). Merge command: svn merge -r 289538:289539 trunk-directory 10.1-directory

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]

Knut Anders Hatlen reassigned DERBY-557:
----------------------------------------

    Assign To: Knut Anders Hatlen

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0

>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Re: [jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
"Bryan Pendleton (JIRA)" <de...@db.apache.org> writes:

> Bryan Pendleton commented on DERBY-557:
> ---------------------------------------
>
> This change looks good to me. The patch applies cleanly to the
> current trunk. I read through the test code and thought it was
> fine. With your patch applied, I ran
>
> java -Dframework=DerbyNetClient -Dverbose=true
> org.apache.derbyTesting.functionTests.harness.RunTest
> jdbcapi/derbyStress.java
>
> and got the expected results (test passed, with the new print
> statement appearing in the output as expected).

Thanks for testing the patch, Bryan. I just realized I forgot to put
conn.close() into the test method. Probably not important since it's
just a regression test, but I'll upload a new patch anyway.

-- 
Knut Anders


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Bryan Pendleton (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12366046 ] 

Bryan Pendleton commented on DERBY-557:
---------------------------------------

This change looks good to me. The patch applies cleanly to the current trunk. I read through the test code and thought it was fine. With your patch applied, I ran

java -Dframework=DerbyNetClient  -Dverbose=true org.apache.derbyTesting.functionTests.harness.RunTest jdbcapi/derbyStress.java

and got the expected results (test passed, with the new print statement appearing in the output as expected).


> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557-regression-test.diff, DERBY-557-regression-test.stat, DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]

Knut Anders Hatlen updated DERBY-557:
-------------------------------------

    Attachment: DERBY-557.diff
                DERBY-557.stat
                derbyall_report.txt

Attached a patch which fixes the bug. The patch ensures that the ResultSets associated with a Statement/PreparedStatement are removed from CommitAndRollbackListeners_ in org.apache.derby.client.am.Connection when the statement is re-executed.

I have run derbyall with only one error (wrong length of encryption key, not related to the patch). I have also run the program in the problem description (both with Statement and PreparedStatement), and the memory usage doesn't increase over time.

Could someone review this patch?

Thanks!

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Kathey Marsden (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-557?page=comments#action_12329559 ] 

Kathey Marsden commented on DERBY-557:
--------------------------------------

That sounds fine to me for the test or just some large constant number of iterations.

If you are adding a new test, I tend to think jdbcapi is a good place and something with a name generic enough  that we could put in a test for DERBY-210.    Alternately you could just change resultset.java to use a small heap if  this  doesn't add a huge amount of time to the test.  


> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]

Knut Anders Hatlen updated DERBY-557:
-------------------------------------

    Attachment: DERBY-557-regression-test-v3.diff

Uploading new diff because of conflict with a recent commit.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557-regression-test-v2.diff, DERBY-557-regression-test-v3.diff, DERBY-557-regression-test.diff, DERBY-557-regression-test.stat, DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]

Knut Anders Hatlen updated DERBY-557:
-------------------------------------

    Attachment: DERBY-557-regression-test-v2.diff

Whops! I forgot to close the connection in the regression test. Uploaded new patch (DERBY-557-regression-test-v2.diff) with conn.close() added. I apologize the noise.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557-regression-test-v2.diff, DERBY-557-regression-test.diff, DERBY-557-regression-test.stat, DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Bernt M. Johnsen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]
     
Bernt M. Johnsen resolved DERBY-557:
------------------------------------

    Resolution: Fixed

Committed revision 377998.


> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557-regression-test-v2.diff, DERBY-557-regression-test-v3.diff, DERBY-557-regression-test.diff, DERBY-557-regression-test.stat, DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]
     
Knut Anders Hatlen closed DERBY-557:
------------------------------------

    Fix Version: 10.1.1.2
     Resolution: Fixed

Fixed in trunk (revision 289539) and 10.1 (revision 306950).

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DERBY-557) Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-557?page=all ]
     
Knut Anders Hatlen closed DERBY-557:
------------------------------------


Regression test checked into revision 377998.

> Client driver gets OutOfMemoryError when re-executing statement without closing ResultSet
> -----------------------------------------------------------------------------------------
>
>          Key: DERBY-557
>          URL: http://issues.apache.org/jira/browse/DERBY-557
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions: 10.1.1.0, 10.1.2.0, 10.2.0.0
>     Reporter: Knut Anders Hatlen
>     Assignee: Knut Anders Hatlen
>     Priority: Minor
>      Fix For: 10.1.2.0, 10.2.0.0, 10.1.1.2
>  Attachments: DERBY-557-regression-test-v2.diff, DERBY-557-regression-test-v3.diff, DERBY-557-regression-test.diff, DERBY-557-regression-test.stat, DERBY-557.diff, DERBY-557.stat, derbyall_report.txt
>
> When re-executing a statement without closing the old ResultSet, some of the old ResultSet's resources are not released, and the network client will eventually get an OutOfMemoryError.
> Example:
> 	Connection c = DriverManager.getConnection("jdbc:derby://localhost/mydb");
> 	PreparedStatement ps = c.prepareStatement("select * from sys.systables");
> 	while (true) {
> 		ResultSet rs = ps.executeQuery();
> 	}
> This code will run for some time and then throw an OutOfMemoryError. Same thing happens with Statement instead of PreparedStatement. If rs.close() is added in the loop, the code works. Explicitly closing the ResultSet should not be necessary according to this quote from the JDBC 3.0 spec:
>   For Select statements, the statement is complete when the associated result set is closed. The result set is closed as soon as one of the following occurs:
>      - all of the rows have been retrieved
>      - the associated Statement object is re-executed
>      - another Statement object is executed on the same connection

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira