]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Missing call to tanvity wait_merging_threads (#12863)
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Fri, 29 May 2026 17:32:15 +0000 (10:32 -0700)
committerGitHub <noreply@github.com>
Fri, 29 May 2026 17:32:15 +0000 (10:32 -0700)
src/documents/search/_backend.py

index 68a9aecadb0c204dbcd420d0ce94f5dfe1502316..2ccd8c86aaba66da5014080b11d1034c899fa1fe 100644 (file)
@@ -220,6 +220,10 @@ class WriteBatch:
         try:
             if exc_type is None:
                 self._writer.commit()
+                # Wait for background merge threads to finish before releasing
+                # the file lock so the next writer doesn't race against an
+                # in-progress merge on the same index files.
+                self._writer.wait_merging_threads()
                 self._backend._index.reload()
             # Explicitly delete writer to release tantivy's internal lock.
             # On exception the uncommitted writer is simply discarded.
@@ -922,6 +926,9 @@ class TantivyBackend:
                 )
                 writer.add_document(doc)
             writer.commit()
+            # Wait for background merge threads to finish so all segments are
+            # fully merged and persisted before the index is considered rebuilt.
+            writer.wait_merging_threads()
             new_index.reload()
         except BaseException:  # pragma: no cover
             # Restore old index on failure so the backend remains usable