[FLINK-39923][state] Fix RocksDB Statistics native memory leak#28489
Open
leekeiabstraction wants to merge 1 commit into
Open
[FLINK-39923][state] Fix RocksDB Statistics native memory leak#28489leekeiabstraction wants to merge 1 commit into
leekeiabstraction wants to merge 1 commit into
Conversation
Close the JNI Statistics wrapper in `RocksDBNativeMetricMonitor.close()` and on partial init in `RocksDBHandle.loadDb()`.
Collaborator
snuyanzin
reviewed
Jun 19, 2026
Comment on lines
+316
to
+319
| if (nativeMetricMonitor != null) { | ||
| // Monitor owns the statistics wrapper. | ||
| IOUtils.closeQuietly(nativeMetricMonitor); | ||
| } else { |
Contributor
There was a problem hiding this comment.
closeQuietly has it's own internal non null check
given that, can it be simplified to just
IOUtils.closeQuietly(nativeMetricMonitor);
IOUtils.closeQuietly(statistics);?
Contributor
There was a problem hiding this comment.
IIUC that might cause double close of statistics (here and in nativeMetricMonitor).
Contributor
There was a problem hiding this comment.
will it be an issue (double closing), asking since closeQuietly should catch all the exceptions?
Or we should keep unclosed in some cases?
anyway it is just a nit pick, so feel free to merge
rkhachatryan
approved these changes
Jun 19, 2026
rkhachatryan
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for the fix.
FYI: @Zakelly, @fredia, @zoltar9264
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.
What changes were proposed in this pull request?
Fix
RocksDBNativeMetricMonitor.close()to invokeStatistics.close()instead of just nulling. Also hoistdbOptions.statistics()into a local inRocksDBHandle.loadDb()so a monitor-constructor failure doesn't orphan the wrapper.Why are the changes needed?
Fix memory leak. When any of the 11 RocksDB ticker metrics is enabled, the TaskManager leaks native memory in proportion to the number of keyed state backend rebuilds e.g. during continuously failing and restarting job.
Verifying this change
Reproduced on
flink:2.2.2, TaskManager container limited to 4 GB cgroup matchingtaskmanager.memory.process.size. Jobs that throwNumberFormatExceptionon every row is submitted withrestart-strategy.fixed-delay.delay=100msand all 11 ticker metrics enabled.See here for reproduction steps: https://github.com/leekeiabstraction/flink/tree/reproduce-rocksdb-statistics-leak/reproduce-rocksdb-statistics-leak
Does this PR introduce any user-facing change?
None.