Skip to content

Fix SharedBytes mmap leak by closing parent arena on close#142460

Merged
ChrisHegarty merged 4 commits intoelastic:mainfrom
ChrisHegarty:shared_bytes_leak
Feb 13, 2026
Merged

Fix SharedBytes mmap leak by closing parent arena on close#142460
ChrisHegarty merged 4 commits intoelastic:mainfrom
ChrisHegarty:shared_bytes_leak

Conversation

@ChrisHegarty
Copy link
Contributor

SharedBytes memory-maps its cache file using Arena.ofShared(), which requires explicit closing to release the mapping. The parent CloseableMappedByteBuffer objects (which own the arenas) were stored in a local variable in the constructor and never closed - only slices (with arena = null) were retained in the IO objects. As a result, mapped memory was never released until JVM exit, leaking the cache file's disk blocks even after the file was deleted.

This is observable in tests that repeatedly create and tear down searchable snapshot infrastructure (e.g. VectorScorerOSQBenchmarkTests), where each iteration leaked a 16+ MB cache file. The fix retains the parent mmap buffers as a field and closes them in closeInternal() via IOUtils.close before closing the file channel.

This issue was caused by the changes in #140371

@ChrisHegarty ChrisHegarty added >bug Team:Distributed Meta label for distributed team. :Distributed/Searchable Snapshots Searchable snapshots / frozen indices. labels Feb 13, 2026
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@elasticsearchmachine
Copy link
Collaborator

Hi @ChrisHegarty, I've created a changelog YAML for you.

Copy link
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM

@ChrisHegarty ChrisHegarty merged commit 890cd94 into elastic:main Feb 13, 2026
35 checks passed
@ChrisHegarty ChrisHegarty deleted the shared_bytes_leak branch February 13, 2026 14:49
sidosera pushed a commit to sidosera/elasticsearch that referenced this pull request Feb 13, 2026
…42460)

SharedBytes memory-maps its cache file using Arena.ofShared(), which requires explicit closing to release the mapping. The parent CloseableMappedByteBuffer objects (which own the arenas) were stored in a local variable in the constructor and never closed - only slices (with arena = null) were retained in the IO objects. As a result, mapped memory was never released until JVM exit, leaking the cache file's disk blocks even after the file was deleted.

This is observable in tests that repeatedly create and tear down searchable snapshot infrastructure (e.g. VectorScorerOSQBenchmarkTests), where each iteration leaked a 16+ MB cache file. The fix retains the parent mmap buffers as a field and closes them in closeInternal() via IOUtils.close before closing the file channel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Distributed/Searchable Snapshots Searchable snapshots / frozen indices. Team:Distributed Meta label for distributed team. v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants