Skip to content

Fix connection leak in MySQLMaxValueIncrementer - #37321

Merged
sbrannen merged 1 commit into
spring-projects:7.0.xfrom
cookie-meringue:fix-connection-leak-in-mysql-incrementer
Oct 3, 2026
Merged

sbrannen merged 1 commit into
spring-projects:7.0.xfrom
cookie-meringue:fix-connection-leak-in-mysql-incrementer

Conversation

@cookie-meringue

Copy link
Copy Markdown
Contributor

Description

When useNewConnection is true (the default), MySQLMaxValueIncrementer obtains a separate connection to update the sequence value.

If auto-commit is enabled on that connection, it temporarily disables it, commits the update, and then re-enables it to restore the original setting.

If commit() or the subsequent setAutoCommit(true) call throws an SQLException, the exception handler throws a DataAccessResourceFailureException before reaching Connection.close().

This can leave the connection unreleased.

Move JdbcUtils.closeConnection(con) into a finally block so cleanup is attempted even when commit or auto-commit restoration fails.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 22, 2026
@sbrannen sbrannen self-assigned this Sep 22, 2026
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Sep 22, 2026
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 3, 2026
@sbrannen sbrannen added this to the 7.0.10 milestone Oct 3, 2026
Move connection cleanup into a finally block so the connection
is closed even if commit or auto-commit restoration fails.

Closes spring-projectsgh-37321

Signed-off-by: cookie-meringue <daehyeon3351@gmail.com>
@sbrannen
sbrannen force-pushed the fix-connection-leak-in-mysql-incrementer branch from 8cf7dfc to a75ee00 Compare October 3, 2026 16:35
@sbrannen
sbrannen changed the base branch from main to 7.0.x October 3, 2026 16:35
@sbrannen
sbrannen merged commit 5e45b9b into spring-projects:7.0.x Oct 3, 2026
3 checks passed
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Fixed via 5e45b9b

@sbrannen

sbrannen commented Oct 3, 2026

Copy link
Copy Markdown
Member

This has been merged into 7.0.x and main.

Thanks

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

Labels

in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants