Skip to content

KAFKA-20287 : Fix CF handle leaks#21751

Open
muralibasani wants to merge 1 commit intoapache:trunkfrom
muralibasani:fix-cf-leaks
Open

KAFKA-20287 : Fix CF handle leaks#21751
muralibasani wants to merge 1 commit intoapache:trunkfrom
muralibasani:fix-cf-leaks

Conversation

@muralibasani
Copy link
Contributor

@muralibasani muralibasani commented Mar 13, 2026

  • RocksDBStore.java — openRocksDB() base method: Added finally block after RocksDB.open() to close all CF handles and db if createColumnFamilies() or mergeColumnFamilyHandleLists() fails.

  • RocksDBStore.java — openDB(): Added finally block with closeNativeResources() to close all partially-initialized native resources if openRocksDB() or cfAccessor.open() fails.

  • RocksDBTimestampedStore.java: Changed RocksIterator from manual close() to try-with-resources, and added finally block to close all CF handles if an exception occurs before the accessor takes ownership.

  • RocksDBMigratingSessionStoreWithHeaders.java: Same as above — try-with-resources for RocksIterator and finally block for CF handle cleanup on failure.

  • RocksDBTimestampedStoreWithHeaders.java — openFromDefaultStore(): Added finally block to close all CF handles if an exception occurs before the accessor takes ownership.

  • RocksDBTimestampedStoreWithHeaders.java — openFromTimestampedStore(): Replaced manual per-handle close() calls (which missed columnFamilies.get(3)) with a single finally block that loops over all handles on failure.

@github-actions github-actions bot added triage PRs from the community streams labels Mar 13, 2026
throw new ProcessorStateException(fatalMessage, fatal);
} catch (final RocksDBException e) {
throw new ProcessorStateException("Error opening store " + name, e);
openRocksDB(dbOptions, columnFamilyOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method internally calls createColumnFamilies() or mergeColumnFamilyHandleLists() which might fail

success = true;
} finally {
if (!success) {
closeNativeResources();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if openRocksDB() or cfAccessor.open() fail

noTimestampColumnFamily.close();
boolean success = false;
try {
try (final RocksIterator noTimestampsIter = db.newIterator(noTimestampColumnFamily)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating with try-resources

boolean success = false;
try {
// Check if default CF has data (plain store upgrade)
try (final RocksIterator defaultIter = db.newIterator(defaultCf)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also updating with try-with resources

boolean success = false;
try {
// verify and close empty Default ColumnFamily
try (final RocksIterator defaultIter = db.newIterator(columnFamilies.get(0))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating here as well in the same way try with resources

noHeadersColumnFamily.close();
boolean success = false;
try {
try (final RocksIterator noHeadersIter = db.newIterator(noHeadersColumnFamily)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating here with try-with resources

@muralibasani muralibasani changed the title Fix CF handle leaks KAFKA-20287 : Fix CF handle leaks Mar 13, 2026
@muralibasani muralibasani marked this pull request as ready for review March 13, 2026 19:56
@github-actions github-actions bot removed the triage PRs from the community label Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant