Skip to content

fix(indexing): release write lock during reindex Finalizing phase - #18

Merged
ManSio merged 1 commit into
mainfrom
fix/reindex-finalizing-deadlock
Aug 28, 2026
Merged

fix(indexing): release write lock during reindex Finalizing phase#18
ManSio merged 1 commit into
mainfrom
fix/reindex-finalizing-deadlock

Conversation

@ManSio

@ManSio ManSio commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Root cause

IndexProjectRunner.run() held db_manager.begin_write() (the global _write_lock RLock) for the ENTIRE reindex job, including the heavy LanceDB optimize() / create_index() calls in _safe_ivf_index(). Running those operations under the global lock deadlocked the 'Finalizing' phase (both processes at 0% CPU, job never completed, ETA grew forever). The reindexing flag was therefore never cleared, permanently blocking concurrent search.

Fix

  • _safe_ivf_index() now releases the global write lock via _suspend_write_lock() around optimize()/create_index(). The reindex guard is_reindexing() (independent of this lock) still blocks concurrent search, so it is safe.
  • create_index is bounded by a timeout + non-blocking executor shutdown, so a stalled LanceDB index build can no longer hang the reindex job forever.

Regression guard

ests/test_reindex_finalizing_deadlock.py:
  • asserts optimize/create_index run with the write lock RELEASED (reproduces the deadlock root cause if it regresses);
  • asserts a hung create_index does not block the Finalizing phase past the timeout.

Test result

python -m pytest tests/test_reindex_finalizing_deadlock.py -q → 2 passed. Existing ests/test_reindex_responsive.py (9) and ests/test_index_runner_deadlock.py (4) still pass.

Root cause: IndexProjectRunner.run() held db_manager.begin_write()
(the global _write_lock RLock) for the entire job, including the heavy
LanceDB optimize()/create_index() calls in _safe_ivf_index(). Running
those under the lock deadlocked the 'Finalizing' phase (both processes
at 0% CPU, job never completed, ETA grew forever).

Fix:
- _safe_ivf_index() now temporarily releases the global write lock via
  _suspend_write_lock() around optimize()/create_index() (reindex guard
  is_reindexing() still blocks concurrent search, so safe).
- Bound create_index with a timeout + non-blocking shutdown so a stalled
  LanceDB index build can no longer hang the reindex job forever.

Regression guard: tests/test_reindex_finalizing_deadlock.py asserts
optimize/create_index run with the lock released and that a hanging
create_index does not block past the timeout.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6410274c-7bb4-4c52-bd66-cab990ec8691


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ManSio
ManSio merged commit 1578a1b into main Aug 28, 2026
13 checks passed
ManSio added a commit that referenced this pull request Aug 28, 2026
Co-authored-by: MSCodeBase Agent <mscodebase@intelligence.local>
Copilot stopped work on behalf of ManSio due to an error August 28, 2026 19:15
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.

1 participant