Skip to content

Commit 549d50f

Browse files
authored
fix: release Lucene lock before retry on corrupt index (#8)
When initLucene() fails during the CheckIndex step, the IndexWriter already holds the write.lock. The catch block deleted index files but never closed the writer, so the retry attempt hit LockObtainFailedException from the same JVM.
1 parent 3bda0b3 commit 549d50f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

docs-core/src/main/java/com/sismics/docs/core/util/indexing/LuceneIndexingHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ public void startUp() throws Exception {
105105
} catch (Exception e) {
106106
// An error occurred initializing Lucene, the index is out of date or broken, delete everything
107107
log.info("Unable to initialize Lucene, cleaning up the index: " + e.getMessage());
108+
109+
// Release the lock before deleting — initLucene may have partially succeeded
110+
if (indexWriter != null) {
111+
try { indexWriter.close(); } catch (Exception ignored) {}
112+
indexWriter = null;
113+
}
114+
if (directory != null) {
115+
try { directory.close(); } catch (Exception ignored) {}
116+
directory = null;
117+
}
118+
108119
Path luceneDirectory = DirectoryUtil.getLuceneDirectory();
109120
Files.walk(luceneDirectory)
110121
.sorted(Comparator.reverseOrder())

0 commit comments

Comments
 (0)