Skip to content

Comments

fix: use persistent event loop in watcher to prevent loop-closed crash#76

Open
svidskiy wants to merge 2 commits intozilliztech:mainfrom
svidskiy:fix/watcher-event-loop
Open

fix: use persistent event loop in watcher to prevent loop-closed crash#76
svidskiy wants to merge 2 commits intozilliztech:mainfrom
svidskiy:fix/watcher-event-loop

Conversation

@svidskiy
Copy link

@svidskiy svidskiy commented Feb 20, 2026

Summary

  • Replaces asyncio.run() with a dedicated persistent event loop (loop.run_until_complete()) in the file watcher callback in core.py

  • asyncio.run() creates and closes a new event loop on every invocation. Async HTTP clients (httpx, used internally by ollama, openai, voyage) cache connections tied to the first loop. When asyncio.run() closes that loop and creates a new one, the cached client attempts to use the dead loop — resulting in RuntimeError: Event loop is closed on the second file change.

  • This is a known httpx limitation — sharing an AsyncClient across multiple asyncio.run() calls is not supported. See also httpx#914.

  • Affects all async embedding providers (OpenAI, Ollama, Voyage, Google), not just Ollama as reported. The local provider is unaffected (no HTTP client).

Fixes #75

Test plan

  • Run memsearch watch . with Ollama provider, modify a file twice — verify both re-indexes succeed without RuntimeError
  • Run memsearch watch . with OpenAI provider, modify a file multiple times — verify no crash
  • Run existing test suite (uv run python -m pytest) — all 26 tests pass

Replace asyncio.run() with a dedicated loop.run_until_complete() in the
file watcher callback. asyncio.run() creates and closes a new event loop
on every call, which breaks async HTTP clients (httpx/ollama/openai/voyage)
that cache connections tied to the first loop.

Fixes zilliztech#75
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.

File wathcer doesn't work on windows

1 participant