Skip to content

Commit 93e0b42

Browse files
fix: keep background worker ownership until stop is confirmed
1 parent 44a8f29 commit 93e0b42

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

utils/search_index.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def _worker() -> None:
708708
_background_stop.clear()
709709
thread = threading.Thread(target=_worker, name="search-index-refresh", daemon=True)
710710
_background_thread = thread
711-
thread.start()
711+
thread.start()
712712

713713

714714
def index_is_usable(projects_dir: str, rules: list[Any]) -> bool:
@@ -822,6 +822,9 @@ def reset_background_for_tests() -> None:
822822
"background search-index worker did not stop within %.0fs",
823823
_BACKGROUND_JOIN_TIMEOUT_S,
824824
)
825+
if not worker_stopped:
826+
_clear_usability_cache()
827+
return
825828
with _index_lock:
826829
_background_started = False
827830
_background_thread = None
@@ -831,8 +834,5 @@ def reset_background_for_tests() -> None:
831834
except OSError:
832835
pass
833836
_background_lock_fd = None
834-
# Leave the stop event set when the worker never terminated so it exits on
835-
# its next loop check and no second worker races it; start() re-clears it.
836-
if worker_stopped:
837-
_background_stop.clear()
837+
_background_stop.clear()
838838
_clear_usability_cache()

0 commit comments

Comments
 (0)