Skip to content

fix(core): close CallableStatement in DerbySnapshotOperation to prevent JDBC resource leak#14743

Merged
KomachiSion merged 1 commit into
alibaba:developfrom
daguimu:fix/derby-snapshot-callable-stmt-leak
Mar 31, 2026
Merged

fix(core): close CallableStatement in DerbySnapshotOperation to prevent JDBC resource leak#14743
KomachiSion merged 1 commit into
alibaba:developfrom
daguimu:fix/derby-snapshot-callable-stmt-leak

Conversation

@daguimu

@daguimu daguimu commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Problem

In DerbySnapshotOperation.doDerbyBackup(), the CallableStatement is created inside a try-with-resources block that only manages the Connection. The statement itself is never closed, causing a JDBC resource leak on each Derby snapshot backup operation.

Root Cause

The CallableStatement was created as a local variable inside the try block rather than being declared in the try-with-resources header:

try (Connection holder = ...) {
    CallableStatement cs = holder.prepareCall(backupSql);  // not auto-closed
    cs.setString(1, backupDirectory);
    cs.execute();
}

While closing the Connection may implicitly close associated statements in some JDBC drivers, the JDBC specification does not guarantee this behavior, and relying on it is a resource management anti-pattern.

Fix

  • Moved the CallableStatement declaration into the try-with-resources header so it is automatically closed after use, consistent with JDBC best practices.

Tests Added

Change Point Test
CallableStatement now auto-closed via try-with-resources testOnSnapshotSaveWithMocks() — added verify(callableStatement).close() to confirm the statement is properly closed after backup execution

Impact

Only affects Derby embedded database backup operations. No behavioral change — backups work identically, but the CallableStatement is now properly closed after each use.

…ackup

The CallableStatement was not included in the try-with-resources block,
causing a JDBC resource leak on each Derby backup operation. This moves
it into the try-with-resources declaration to ensure proper cleanup.
@github-actions

Copy link
Copy Markdown

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@KomachiSion KomachiSion added the kind/enhancement Category issues or prs related to enhancement. label Mar 31, 2026
@KomachiSion KomachiSion added this to the 3.2.1 milestone Mar 31, 2026
@KomachiSion
KomachiSion merged commit c83121b into alibaba:develop Mar 31, 2026
2 checks passed
@daguimu
daguimu deleted the fix/derby-snapshot-callable-stmt-leak branch March 31, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/plugin kind/enhancement Category issues or prs related to enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants