Skip to content

SOLR-18551: Prevent mmap leak in IndexFetcher - #5173

Open
gerlowskija wants to merge 2 commits into
apache:mainfrom
gerlowskija:SOLR-18551-avoid-mmap-leak-in-indexfetcher
Open

gerlowskija wants to merge 2 commits into
apache:mainfrom
gerlowskija:SOLR-18551-avoid-mmap-leak-in-indexfetcher

Conversation

@gerlowskija

@gerlowskija gerlowskija commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-18551

Description

Prior to this commit, IndexFetcher's "slowFileExists" method checked existence by attempting to open and then close the file. When MMapDirectoryFactory was in use, this "open" creates an mmap that remains somewhat "leaked" until the DirectoryReader is closed, due to idiosyncracies in how Lucene pools mmaps into "arenas" based on their segment.

This caused a pretty significant mmap leak in later Solr 9.x releases. It's less likely to impact Solr 10.x or later versions due to changes in Lucene, but it's still possible.

Solution

This commit fixes the issue by reworking IndexFetcher's "exists" check. Now instead of opening the file, IndexFetcher does a size-check which can be used to determine existence with only an OS 'stat' call and without creating an mmap at all.

Tests

None. I'd like to write tests here, but I can't think of a good way to write an automated test for this. If anyone has ideas I'm very open to suggestions!

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added a changelog entry for my change

Prior to this commit, IndexFetcher's "slowFileExists" method checked
existence by attempting to open and then close the file.  When
MMapDirectoryFactory was in use, this "open" creates an mmap that
remains somewhat "leaked" until the DirectoryReader is closed, due to
idiosyncracies in how Lucene pools mmaps into "arenas" based on their
segment.

This caused a pretty significant mmap leak in later Solr 9.x releases.
It's less likely to impact Solr 10.x or later versions due to changes in
Lucene, but it's still possible.

This commit fixes the issue by reworking IndexFetcher's "exists" check.
Now instead of opening the file, IndexFetcher does a size-check which
can be used to determine existence with only an OS 'stat' call and
without  creating an mmap at all.

@jaykay12 jaykay12 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.

+1 on using fileLength - definitely better than READONCE for just existence check.

Please fix the PR title to SOLR-18551
also, will this be backported in 9.x branch?

}

/**
* Returns true if the file exists (can be opened), false if it cannot be opened, and (unlike

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.

Lets refresh this javadoc as well?

@dsmiley dsmiley 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.

the PR template 1st line includes a JIRA URL with that is to be edited. Please retain that. Otherwise, as a reviewer I have extra steps to go look in JIRA beyond clicking a link.

@dsmiley dsmiley added this to the 9.x milestone Oct 17, 2026
@gerlowskija gerlowskija changed the title SOLR-18851: Prevent mmap leak in IndexFetcher SOLR-18551: Prevent mmap leak in IndexFetcher Oct 19, 2026
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.

3 participants