Skip to content

Auto-close result returned from getResultSet (1.5) - #783

Merged
staticlibs merged 1 commit into
duckdb:v1.5-variegatafrom
staticlibs:result_autoclose_15
Aug 3, 2026
Merged

Auto-close result returned from getResultSet (1.5)#783
staticlibs merged 1 commit into
duckdb:v1.5-variegatafrom
staticlibs:result_autoclose_15

Conversation

@staticlibs

Copy link
Copy Markdown
Member

This is a backport of the PR #781 to v1.5-variegata stable branch.

ResultSet objects returned from Statement#executeQuery() is closed automatically, when its parent statement is closed.

Per JDBC specification:

When a Statement object is closed, its current ResultSet object, if
one exists, is also closed.

Though, when a ResultSet is obtained from Statement#execute() + Statement.getResultSet(), such ResultSet was not considered to be a "current ResultSet object" because, according to the spec:

This method [Statement.getResultSet()] should be called only once per
result.

Thus such result set was not closed automatically.

Such code is used in practice and it has started to cause a memory leak (of the full materialized result set) after #533 was added.

This PR fixes the leak by retaining the ResultSet, returned from Statement.getResultSet(), as a "current ResultSet object" and closing it automatically on Statement close.

Testing: new tests added to TestClosure

Fixes: #780

This is a backport of the PR duckdb#781 to `v1.5-variegata` stable branch.

`ResultSet` objects returned from `Statement#executeQuery()` is closed
automatically, when its parent statement is closed.

Per JDBC specification:

> When a Statement object is closed, its current ResultSet object, if
> one exists, is also closed.

Though, when a `ResultSet` is obtained from `Statement#execute()` +
`Statement.getResultSet()`, such `ResultSet` was not considered to be a
"current ResultSet object" because, according to the spec:

> This method [`Statement.getResultSet()`] should be called only once per
> result.

Thus such result set was not closed automatically.

Such code is used in practice and it has started to cause a memory leak
(of the full materialized result set) after duckdb#533 was added.

This PR fixes the leak by retaining the `ResultSet`, returned from
`Statement.getResultSet()`, as a "current ResultSet object" and closing
it automatically on `Statement` close.

Testing: new tests added to `TestClosure`

Fixes: duckdb#780
@staticlibs
staticlibs merged commit ec0241b into duckdb:v1.5-variegata Aug 3, 2026
15 checks passed
@staticlibs
staticlibs deleted the result_autoclose_15 branch August 3, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant