Skip to content

fix(searcher): bound per-path wait and non-blocking shutdown - #2194

Closed
RerankerGuo wants to merge 1 commit into
MemTensor:mainfrom
RerankerGuo:fix/issue-2134-searcher-thread-leak
Closed

fix(searcher): bound per-path wait and non-blocking shutdown#2194
RerankerGuo wants to merge 1 commit into
MemTensor:mainfrom
RerankerGuo:fix/issue-2134-searcher-thread-leak

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

Summary

  • Bound each retrieval path's Future.result() wait to 30s so a slow / blocked path (e.g. hanging Neo4j / HTTP call) cannot stall the whole searcher.
  • Replaced the with ContextThreadPoolExecutor(...) block with explicit executor.shutdown(wait=False) in a finally: block so straggling threads never pin the pool.
  • Added a unit test verifying _retrieve_paths returns even when one path is artificially slow.

Closes #2134.

Verification

  • ruff format / ruff check clean on changed lines.
  • New test test_retrieve_paths_timeout_releases_executor simulates a 5s-hanging path and asserts the total elapsed is well below the 30s bound.

Checklist

  • Local ruff format / check ran clean.
  • Tests added for the new timeout / shutdown behaviour.
  • Backward compatible — happy-path behaviour unchanged.

Searcher._retrieve_paths previously joined every retrieval path with
Future.result() (no timeout) inside a ContextThreadPoolExecutor
context-manager, so a single slow / blocked path (e.g. a hanging
Neo4j or HTTP call) would stall the whole searcher and pin worker
threads until process exit.

Add a per-path timeout (30s) on each future and release the pool via
executor.shutdown(wait=False) in a finally block, guaranteeing no
thread leak on any pathological path. Added a unit test covering the
slow-path branch.
Closes #2134.
@Memtensor-AI Memtensor-AI added area:memory 记忆存储、检索、更新、召回逻辑 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Aug 3, 2026
@RerankerGuo

Copy link
Copy Markdown
Contributor Author

Closing this as a semantic duplicate of #2134, which already implements the full #1273 fix across all four retrieval executors and is the active implementation assigned through the issue. This PR only covered _retrieve_paths, and its Closes #2134 reference was also incorrect. Keeping one implementation avoids competing review work.

@RerankerGuo RerankerGuo closed this Aug 5, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (5/5 executed). memos_python_core/changed-repo-python: 5/5. Duration: 11s

Branch: fix/issue-2134-searcher-thread-leak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory 记忆存储、检索、更新、召回逻辑 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants