[ISSUE #10218] Fix resource leak in DumpCompactionLogCommand#10219
Open
daguimu wants to merge 1 commit intoapache:developfrom
Open
[ISSUE #10218] Fix resource leak in DumpCompactionLogCommand#10219daguimu wants to merge 1 commit intoapache:developfrom
daguimu wants to merge 1 commit intoapache:developfrom
Conversation
05ea91e to
7eaff91
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10219 +/- ##
=============================================
- Coverage 48.96% 48.87% -0.09%
+ Complexity 13385 13365 -20
=============================================
Files 1373 1373
Lines 99904 99907 +3
Branches 12901 12902 +1
=============================================
- Hits 48913 48827 -86
- Misses 45062 45133 +71
- Partials 5929 5947 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DumpCompactionLogCommand.execute()creates aRandomAccessFileto obtain aFileChannel, but neither resource is ever closed. The anonymousRandomAccessFileis immediately discarded after.getChannel(), making it impossible to close. This leaks file descriptors on every invocation.Root Cause
The code uses
new RandomAccessFile(fileName, "rw").getChannel()as a one-liner, discarding theRandomAccessFilereference. Neither theRandomAccessFilenor theFileChannelis wrapped in a try-with-resources block or closed in a finally block.Fix
RandomAccessFileandFileChannelin a try-with-resources statement to ensure they are always closed after use."rw"to"r"since the command only reads (dumps) the compaction log, it does not need write access. TheMapModewas also changed fromREAD_WRITEtoREAD_ONLYto match.Tests Added
testExecuteWithValidFile()— writes a message, dumps it, verifies no resource leak (file still accessible)testExecuteWithEmptyFile()— verifies graceful handling of empty filestestExecuteWithNonExistentFile()— verifies SubCommandException is throwntestExecuteWithoutFileOption()— verifies error message is printed without exceptionImpact
Only affects the
dumpCompactionLogCLI tool. No changes to broker runtime or message processing logic.Fixes #10218