fix(storage): close the object iterator in isNonEmptyBucket (MOCA-413)#298
Merged
Merged
Conversation
isNonEmptyBucket created an object-store iterator and returned iter.Valid() without ever calling iter.Close(), leaking a store iterator on every call (it runs via DeleteBucket). Add `defer iter.Close()` so the iterator is always released; defer runs after iter.Valid() is evaluated and the function is not in a loop, so behavior is unchanged. Add a whitebox behavior regression test (TestIsNonEmptyBucket): empty bucket -> false, a bucket with an object -> true, plus per-bucket isolation. A leak-catching test is impractical because moca's KVStore does not panic on write-while-iterator-open, so the dangling iterator is not observable from a unit test. MOCA-413 Signed-off-by: puneetmahajan <59960662+puneet2019@users.noreply.github.com>
ec0d084 to
d4a37e1
Compare
phenix3443
approved these changes
Jul 1, 2026
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.
MOCA-413 — resource leak in
x/storage/keeperisNonEmptyBucketLeak
isNonEmptyBucket(called fromDeleteBucket) created an object-store iterator and returnediter.Valid()without closing it — leaking a store iterator on every call:Fix
Add
defer iter.Close().deferruns afteriter.Valid()is evaluated and the function isn't in a loop, so the iterator is always released and behavior is unchanged.Test
New whitebox behavior test
TestIsNonEmptyBucket(package keeper, since the function is unexported): empty bucket → false, bucket with an object → true, per-bucket isolation. A leak-catching test isn't practical — moca's KVStore doesn't panic on write-while-iterator-open, so the dangling iterator isn't observable from a unit test; the test guards behavior alongside the fix.Verification
go build ./x/storage/...,go vet ./x/storage/keeper/,gofumpt, andgo test ./x/storage/keeper/...all pass.