JDBCDataStore resource leak

Description

I've found a resource leak in data/src/org/geotools/data/jdbc/JDBCDataStore.java

The method executeQuery beginning on line 786 does not properly clean up it's database resources.

Adding the following finally block to the try catch will resolve the issue:
finally
{
JDBCUtils.close(rs);
JDBCUtils.close(statement);
JDBCUtils.close(conn, transaction, null);
}

Also recommend moving return statement out side of try/catch/finally block using method local variable to hold "queryData".

Currently the symptom of this on a PostGIS enabled database is ever increasing connections being made to the database being left in a state of "idle in transaction". Currently the code, as written, will only close connection resources when there is an exception. This is a bad practice as those connections (and in turn transactions) are tied to managed objects which are referenced by a pool manager which exists for the duration of the container. The garbage collector will not clean these up.

This is only one instance of this. Recommend an investigation of any code where database connections are allocated and utilized for similar pattern. Should be a no brainer to correct.

Environment

None

Activity

Show:
codehaus
April 10, 2015, 2:57 PM

CodeHaus Comment From: seangeo - Time: Mon, 10 May 2004 19:32:58 -0500
---------------------
This is by design. The connection and associated objects are closed when the FeatureReader is closed. This allows for 'streaming' of the results rather than reading them all into memory before returning them to the user.

So make sure you are closing your FeatureReader/FeatureSource and in turn your connections should be closed.

PS. Jody Garnett has turned up a problem with PostGis connections and transactions. This might be related to your initial problem.

codehaus
April 10, 2015, 2:57 PM

CodeHaus Comment From: aaime - Time: Sun, 28 Nov 2010 02:57:27 -0600
---------------------
Mass closing all issues that have been in "resolved" state for 2 months or more without any feedback or update

Assignee

Unassigned

Reporter

codehaus

Triage

None

Components

Affects versions

Priority

High
Configure