Skip to content

Release queryForStream resources if warning handling fails - #37483

Open
lejuho wants to merge 1 commit into
spring-projects:mainfrom
lejuho:jdbc-stream-cleanup
Open

lejuho wants to merge 1 commit into
spring-projects:mainfrom
lejuho:jdbc-stream-cleanup

Conversation

@lejuho

@lejuho lejuho commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

queryForStream runs with closeResources=false and hands cleanup to the returned Stream's close handler. However, handleWarnings is invoked after the Stream has been created; with ignoreWarnings=false and a statement warning present, it throws SQLWarningException (a RuntimeException) which bypasses the catch (SQLException) cleanup. Since the Stream never reaches the caller, the ResultSet, Statement and Connection are leaked. This also affects NamedParameterJdbcTemplate and JdbcClient streams.

This change closes the Stream (releasing all resources) if warning handling fails, for both the Statement and PreparedStatement paths. The closeResources contract is unchanged. Regression tests cover both paths.

When ignoreWarnings is disabled and the statement reports a warning,
JdbcTemplate.execute throws SQLWarningException after the stream
callback has acquired the ResultSet. Since queryForStream executes
with closeResources=false and the Stream is never returned, the
ResultSet, Statement and Connection were leaked.

Close the stream (and thereby its resources) in that case.

Signed-off-by: lejuho <zedd1324@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants