Fix FSDirectory resource leak when IndexWriter construction fails in HNSW vector index#18964
Conversation
|
please rebase |
|
@xiangfu0 please take a look when you get a chance |
In both HnswVectorIndexCreator and MutableVectorIndex, the constructor opens an FSDirectory then constructs an IndexWriter. If IndexWriter throws (e.g. due to a corrupt or locked index directory, codec init failure, or OOM), the already-opened FSDirectory was silently leaked: the catch block only wrapped and rethrew the exception without closing the directory. On systems that create many vector indexes (or under repeated reload failures), this exhausts file descriptors over time. Fix: use local variables for the Directory and IndexWriter so they are accessible in the catch block. Close the directory (or the writer, which owns the directory when construction succeeds) before rethrowing. For MutableVectorIndex also delete the temporary index directory so it does not accumulate stale temp files on failure. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
5ee7efe to
9402863
Compare
|
@xiangfu0 please take a look when you get a chance |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18964 +/- ##
============================================
- Coverage 65.05% 65.05% -0.01%
Complexity 1403 1403
============================================
Files 3399 3399
Lines 212808 212832 +24
Branches 33568 33571 +3
============================================
+ Hits 138443 138451 +8
- Misses 63223 63236 +13
- Partials 11142 11145 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@xiangfu0 @shounakmk219 would appreciate a review when you get a chance. This PR fixes a file-descriptor leak in |
Summary
Both
HnswVectorIndexCreatorandMutableVectorIndexopen anFSDirectoryin their constructors and then immediately construct anIndexWriterover it. IfIndexWriterconstruction throws — e.g. due to a locked or corrupt index directory, a codec initialization failure, or anOutOfMemoryError— the already-openedFSDirectoryis silently leaked: thecatchblock wraps and rethrows the exception without ever callingclose()on the directory.On servers that repeatedly create or reload vector indexes under error conditions, this accumulates unclosed file descriptors until the OS limit is hit, causing new index creations to fail with "Too many open files".
Root cause
Fix
Use local variables so the directory is accessible in the
catchblock. Close the directory (or writer, if construction succeeded) before rethrowing. InMutableVectorIndex, also delete the temporary index directory so stalegetTempDirectory()subdirectories don't accumulate on failure.Files changed
HnswVectorIndexCreator.java— offline segment generation pathMutableVectorIndex.java— realtime ingestion path (also cleans up temp dir on failure)Test plan
./mvnw checkstyle:check -pl pinot-segment-local— 0 violationscc @xiangfu0 @raghavyadav01 @Jackie-Jiang