Skip to content

fix(in-memory): resolve orphaned skiplist arena leak on Close#2295

Open
parthbhanti22 wants to merge 1 commit into
dgraph-io:mainfrom
parthbhanti22:fix/issue-2205-skiplist-leak
Open

fix(in-memory): resolve orphaned skiplist arena leak on Close#2295
parthbhanti22 wants to merge 1 commit into
dgraph-io:mainfrom
parthbhanti22:fix/issue-2205-skiplist-leak

Conversation

@parthbhanti22
Copy link
Copy Markdown

Description

Fixes #2205.

Root Cause:
When Badger is configured with opt.InMemory = true, the db.close() function triggers an early return. This prevents the cleanup logic from iterating over the immutable memtables slice (db.imm). Because mmap allocations bypass Go's GC, failing to explicitly call DecrRef() on these memtables leaves the skl.Arena allocations orphaned in memory indefinitely.

The Fix:
Added an explicit iteration over db.imm to decrement reference counts on all immutable memtables prior to the early return in the in-memory shutdown sequence.

Verification:
Included issue_2205_test.go to aggressively cycle in-memory database instantiation.

  • Before: pprof inuse_space showed ~83GB of retained skl.newArena allocations across 1000 iterations.
  • After: Retained arenas dropped to 0 bytes.

All tests in ./test.sh pass locally.

Checklist

  • Code compiles correctly and linting passes locally
  • Tests added for new functionality, or regression tests for bug fixes added as applicable
ppof1 ppof2

Signed-off-by: Parth Bhanti <parthbhanti22@gmail.com>
@parthbhanti22 parthbhanti22 requested a review from a team as a code owner June 5, 2026 12:57
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 5, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

In memory databases leak memory on Close/DropAll due to orphaned skiplists

2 participants