Skip to content

GH-31: fix index race between concurrent instances - #32

Merged
blainemotsinger merged 1 commit into
mainfrom
GH-31
Sep 28, 2026
Merged

blainemotsinger merged 1 commit into
mainfrom
GH-31

Conversation

@blainemotsinger

@blainemotsinger blainemotsinger commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #31.

A second knowledge-mcp instance sharing the single-writer index blocked in bleve. Open (bbolt flock has no timeout) before serving MCP, so clients hit their handshake timeout.

  • search.NewLazyIndex + OpenBackground: the index opens on a background goroutine after the MCP server starts; single-flight, self-recovering
  • WaitOpen bounds tool waits: Query/Add return ErrIndexLocked (2s) instead of blocking forever while another instance holds the lock
  • the pending open completes on its own once the lock frees (no restart)

Tests: 3 new in search/race_test.go (locked open, query while locked, add while locked). Full suite, go vet, gofmt, and -race pass. Manual e2e (two
live servers, shared index): locked handshake 0.02s, bounded error at 2.0s, self-recovery after the first instance exits.

@blainemotsinger
blainemotsinger merged commit e49a7c8 into main Sep 28, 2026
2 checks passed
@blainemotsinger
blainemotsinger deleted the GH-31 branch September 28, 2026 16:19
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.

fix index race

1 participant