Skip to content

ZOOKEEPER-5093: Ensure snapLog closed even if txnLog close throws in FileTxnSnapLog.close - #2445

Merged
kezhuw merged 3 commits into
apache:masterfrom
shoemoney:fix/zk-close-leak
Sep 18, 2026
Merged

kezhuw merged 3 commits into
apache:masterfrom
shoemoney:fix/zk-close-leak

Conversation

@shoemoney

@shoemoney shoemoney commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

When transaction-log cleanup throws an IOException, FileTxnSnapLog.close() skips snapshot cleanup and leaves its resources open.

Add IOUtils.closeAll(Closeable...) to attempt every non-null closeable in order, rethrow the first IOException, and attach subsequent exceptions as suppressed. FileTxnSnapLog.close() clears its references and delegates cleanup to the helper. SnapShot now extends Closeable.

Added five helper tests and a persistence regression covering both close failures, suppressed exceptions, and repeated close calls. The regression fails against current upstream FileTxnSnapLog.close() because snapShot.close() is never invoked, and passes with this change.

Validation on JDK 25: all 42 persistence/helper tests passed, with zero SpotBugs findings, zero Checkstyle violations, and a passing Apache RAT license check.

mvn -B -ntp -Pfull-build -pl zookeeper-server -am \
  '-Dtest=IOUtilsTest,org.apache.zookeeper.server.persistence.*Test' \
  -Dsurefire.failIfNoSpecifiedTests=false -Dsurefire-forkcount=1 \
  verify spotbugs:check checkstyle:check
mvn -B -ntp -pl zookeeper-server -am apache-rat:check

Fix verified RED->GREEN. FileTxnSnapLog.close leaks snapLog if txnLog close throws at FileTxnSnapLog.java:623
@shoemoney shoemoney closed this Aug 25, 2026
@shoemoney shoemoney reopened this Aug 25, 2026
@shoemoney

Copy link
Copy Markdown
Contributor Author

CI failure is pre-existing flaky ZookeeperServerClusterTest.testStart:116 (single failure out of 3262 tests, unrelated to single-file FileTxnSnapLog.close fix). Checkstyle 0 violations, spotbugs skipped. Retriggering Jenkins build.

@kezhuw

kezhuw commented Sep 15, 2026

Copy link
Copy Markdown
Member

Shall we generalize this ? For example, add IOUtils.closeAll to close Closeable without swallowing IOException .

@shoemoney

Copy link
Copy Markdown
Contributor Author

@kezhuw Added IOUtils.closeAll(Closeable...) in 505e71b, with FileTxnSnapLog.close() delegating to it and SnapShot extending Closeable. The helper attempts every non-null closeable, rethrows the first IOException, and suppresses subsequent exceptions.

All 42 persistence/helper tests pass on JDK 25; SpotBugs, Checkstyle, and Apache RAT pass. The new cleanup regression fails against upstream because snapshot close is skipped, then passes with this change.

@kezhuw kezhuw changed the title fix(zookeeper): ensure snapLog closed even if txnLog close throws ZOOKEEPER-5093: Ensure snapLog closed even if txnLog close throws in FileTxnSnapLog.close Sep 16, 2026
@kezhuw

kezhuw commented Sep 16, 2026

Copy link
Copy Markdown
Member

Do you have an apache jira account so I can assign ZOOKEEPER-5093 to you ? You may have to request a jira account those days in sign up process. @shoemoney

@kezhuw
kezhuw merged commit 427f959 into apache:master Sep 18, 2026
17 checks passed
kezhuw pushed a commit that referenced this pull request Sep 18, 2026
…FileTxnSnapLog.close

Reviewers: kezhuw
Author: shoemoney
Closes #2445 from shoemoney/fix/zk-close-leak

(cherry picked from commit 427f959)
Signed-off-by: Kezhu Wang <kezhuw@apache.org>
@kezhuw

kezhuw commented Sep 18, 2026

Copy link
Copy Markdown
Member

Merged!

Thank you for your contribution! @shoemoney

I have assigned ZOOKEEPER-5093 to myself for now. Please ping me your jira id once you have one so I can assign it to you.

@shoemoney

Copy link
Copy Markdown
Contributor Author

Thanks for the merge, @kezhuw. I did not have a Jira account, so I requested one through selfserve.apache.org under the ZooKeeper project with the username shoemoney. It is verified on my side and waiting on PMC review. I will ping you here once it exists so ZOOKEEPER-5093 can be reassigned.

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.

2 participants