fix(search): guard Searcher index against concurrent rebuild double-close#8
Open
walcz-de wants to merge 1 commit into
Open
Conversation
…lose IndexSkills closes and recreates the bleve index without synchronization. The GitSyncer starts one goroutine per configured repo, each calling RebuildIndex -> IndexSkills. When two rebuilds overlap, the second s.index.Close() closes an already-closed index and panics with "close of closed channel", crashing the host process (observed in LocalAI's periodic skill git-sync taking down the whole LLM server). Add a sync.RWMutex to Searcher: IndexSkills and Close take the write lock, Search takes the read lock (held across index.Search so a concurrent rebuild cannot Close the index mid-search). Includes a -race regression test that panics without the lock and passes with it. Signed-off-by: Stefan Walcz <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01TudBpPAvgnGgWpYwoe7ZZs
walcz-de
added a commit
to walcz-de/LocalAI
that referenced
this pull request
Jul 11, 2026
…nt-rebuild double-close fix) Pin github.com/mudler/skillserver to our fork carrying the Searcher RWMutex fix (walcz-de/skillserver@62ca218). Without it, concurrent RebuildIndex -> IndexSkills calls (one GitSyncer goroutine per configured skill git-repo) double-close the bleve index and panic "close of closed channel", crashing the whole LocalAI server — this took the stack down on 2026-07-11 05:20. Same replace-directive pattern as the LocalAGI override. Upstream PR: mudler/skillserver#8. Once merged upstream and LocalAI bumps its skillserver pin, this replace can be dropped. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01TudBpPAvgnGgWpYwoe7ZZs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Searcher.IndexSkillscloses and recreates the bleve index without any synchronization:GitSyncertriggers a re-index via theonUpdatecallback (RebuildIndex→IndexSkills), and re-index is driven per configured repo. When two rebuilds overlap (e.g. multiple git repos syncing, or a periodic sync racing a manual one), the seconds.index.Close()closes an already-closed index and the process panics:This is not just an internal error — it crashes the host process. We hit it downstream in LocalAI, where the periodic skill git-sync took down the whole LLM server.
Searchhas the mirror race: it reads/usess.indexwhileIndexSkillsswaps and closes it →search failed: index is closed.Fix
Add a
sync.RWMutextoSearcher:IndexSkillsandClosetake the write lock.Searchtakes the read lock, held acrossindex.Searchso a concurrent rebuild cannotClosethe index mid-search.Minimal and surgical — no behavioural change on the single-threaded path.
Test
Adds a
-raceregression test (pkg/domain/search_test.go) that runs 8 concurrentIndexSkillscalls plus interleaved searches. It panics with "close of closed channel" without the fix and passes with it (verified undergo test -race).