Skip to content

Fix SearchIndex directory leak - #51

Merged
kelunik merged 2 commits into
masterfrom
fix-searchindex-directory-leak
Aug 31, 2026
Merged

kelunik merged 2 commits into
masterfrom
fix-searchindex-directory-leak

Conversation

@kelunik

@kelunik kelunik commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

kelunik and others added 2 commits August 31, 2026 14:53
… order

initLookupOutputStream() and openSearcher() opened FSDirectory instances into
local variables that were never retained on the object, so closing the
IndexWriter / DirectoryTaxonomyReader built on top of them never closed the
Directory itself — closing a Lucene IndexWriter/Reader does not close the
Directory it was opened on. close() also closed the writers before the
searcher/reader built on top of them, with no try/finally, so a failure
partway through skipped the remaining shutdown steps.

Net effect: native file handles could stay open after SearchIndex.close()
returned, occasionally surfacing downstream as background writes into the
index directory after teardown assumed it was done (e.g. a
DirectoryNotEmptyException from a temp-dir cleanup right after close()).

Retain the Directory instances as fields and close everything via
IOUtils.close(), which closes the searcher/reader before the writers and
guarantees every Closeable is closed even if an earlier one throws.

Added a regression test asserting the retained Directory fields are actually
closed after SearchIndex.close().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kelunik
kelunik merged commit 0d06ffc into master Aug 31, 2026
1 check passed
@kelunik
kelunik deleted the fix-searchindex-directory-leak branch August 31, 2026 13:06
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.

2 participants