Skip to content

[ISSUE #10912] Close RocksDB Slice objects in scanExpiredRecords - #10914

Open
123123213weqw wants to merge 1 commit into
apache:developfrom
123123213weqw:wangyue/issue-10912-rocksdb-slice-leak
Open

[ISSUE #10912] Close RocksDB Slice objects in scanExpiredRecords#10914
123123213weqw wants to merge 1 commit into
apache:developfrom
123123213weqw:wangyue/issue-10912-rocksdb-slice-leak

Conversation

@123123213weqw

@123123213weqw 123123213weqw commented Aug 12, 2026

Copy link
Copy Markdown

What is the purpose of the change

Fix #10912.

scanExpiredRecords() created two RocksDB Slice objects as iterator bounds and never closed them, leaking native memory on every POP revive scan. The slices are now created as named resources inside the try-with-resources block so they are closed together with the ReadOptions and iterator.

Brief changelog

  • PopConsumerRocksdbStore.scanExpiredRecords(): move the two Slice bounds into try-with-resources

How was this patch verified

  • RocksDB Slice implements AutoCloseable via AbstractNativeReference, so the try-with-resources block closes it deterministically alongside ReadOptions and RocksIterator
  • git diff --check clean

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

This PR contains the exact same fix as #10913 — both modify PopConsumerRocksdbStore.scanExpiredRecords() to properly close RocksDB Slice objects. The diffs are identical.

Recommendation: Since #10913 was submitted first (same date, earlier PR number), consider closing this one as a duplicate to avoid merge conflicts and reduce review burden on maintainers.

The underlying fix is correct — Slice objects must be explicitly closed to prevent native memory leaks.


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Summary

This PR fixes a resource leak in PopConsumerRocksdbStore.scanExpiredRecords where RocksDB Slice objects were not being properly closed.

Findings

  • [Critical] PopConsumerRocksdbStore.java:147 — RocksDB Slice objects implement Closeable and must be closed to prevent native memory leaks. The fix properly wraps them in try-with-resources.
  • [Info] This is a classic native memory leak pattern. Without proper cleanup, long-running brokers would gradually consume more off-heap memory.

Overall

Good fix for a resource leak. RocksDB objects hold native memory that won't be reclaimed by the JVM garbage collector, so explicit cleanup is essential.


Automated review by RockteMQ-AI

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

Properly closes RocksDB Slice objects in scanExpiredRecords using try-with-resources. This fixes a native memory leak — Slice holds off-heap memory that won't be reclaimed by GC.

Clean fix, LGTM.


Automated review by github-manager-bot

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.

[Bug] PopConsumerRocksdbStore leaks RocksDB Slice objects

2 participants