Statement leak on the connector datasource?



On the project I am working on, we detect a "Too Many Open Cursor" on a data source connector. This connector access anc Oracle Database.

Looking at the data source Connector source

In line 138:

if (command.startsWith("SELECT")) {
resultSet =;
result.put("resultset", resultSet);
In the disconnect:

public void disconnect() throws ConnectorException {
if (resultSet != null) {
try {
} catch (Exception e) {
throw new ConnectorException(e);

So, assuming we pass correctly in the disconnect every time (even when the setOutputParameters() failed with an exception ?), the ResultSet is close.

But what about the statement ? do

public ResultSet select(final String query) throws SQLException {
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
return statement.executeQuery(query);

This statement is never close explicitly then.

So questions are:

1/ if the setOuputParameters() failed, is the disconnect() is correctly cause ?

2/ the statement.close() is not called. Is that not an issue? If the statement.close() is called when the object is deleted, then it depends on the Garbage Collector. Before this guy runs, a lot of statements may be waiting, causing the issue.

Indeed, in the database connector, the connection is close at the disconnect(). But on the datasource connector, the connection.close() does not close the connection, just release it to the pool. Any open resources are kept.

3/What happens if, in the groovy, a developer does


Is that impact the variable on the Java side? If yes, then the disconnect() will never close the ResultSet.

No answers yet.