[Bug]: Read-only collection concurrent query triggers permanent futex deadlock (process hangs, never recovers)
メンテナーはふだん 1 日以内に返信
@richyreachy がすでに取り組んでいます。
2026年10月21日 から。
評価
この issue はまだ評価されていません。
説明
Description
Summary
Opening a collection in read-only mode and issuing concurrent query() calls — either from many threads in one process, or from two separate processes that open the same collection path — causes the whole process to deadlock indefinitely. Every in-flight query thread blocks inside collection.Query() and never returns; CPU usage drops to idle; the process cannot be recovered except by kill -9.
This happens with no writer at all — purely concurrent read-only queries.
The blocking call site (from py-spy dumps) is:
zvec/executor/query_executor.py:139 docs = collection.Query(query)
-> C++ proxima internal lock -> futex_wait (kernel), never wakes
Environment
- zvec 0.7.0 (PyPI wheel)
- Python 3.14.4
- Linux x86_64, kernel 6.18.54 (WSL2 / Ubuntu 26.04)
- Collection: ~668 docs, 768-dim FP32 dense vectors, 1000+ index shards (embedding.index.N.proxima)
Root cause (hypothesis)
A read-only query() path in the proxima C++ core performs internal index state mutation (mtime / segment bookkeeping) under a shared lock. When multiple queries (threads or processes) enter this path concurrently, the lock acquisition/release sequence forms a circular wait (futex_do_wait with no waker), deadlocking the entire process. Because the lock is process-internal, it also deadlocks across two processes that map the same on-disk collection.
Workaround we applied (partial)
Serializing all queries inside a single process with a reentrant lock eliminates the intra-process deadlock. This does NOT fix the cross-process case (two processes opening the same collection still deadlock each other). A robust fix likely needs an internal lock safe under concurrent read-only access and/or a cross-process file lock (cf. issue #247).
Impact
Any deployment that serves read-only zvec collections under concurrency (multi-threaded server, or multiple processes sharing one collection path) is vulnerable to a total, unrecoverable hang of the serving process.
Related issues
- #247 Concurrent multi-process access support without FileLock (directly relevant to the cross-process deadlock)
- #714 SIGSEGV under concurrent fetch + insert when the writer crosses a segment switch (requires a writer; ours is read-only)
- #8 delete_by_filter with invert field causes a hang (another hang symptom)
Steps to Reproduce
1. Create a collection with FP32 vectors and insert ~20k random docs.
2. Build the index (optimize()) and close.
3. Reopen the SAME collection in read-only mode:
zvec.open(path, zvec.CollectionOption(read_only=True, enable_mmap=False))
4. Spawn ~32 threads, each looping concurrent collection.query(...) calls.
5. Within seconds~minutes the process deadlocks: all query threads hang, CPU goes idle, the process is wedged until kill -9.
Cross-process variant: run steps 3-4 in TWO separate processes that open the same read-only collection path; both hang.
Minimal stress script:
import zvec, numpy as np, threading, time
DIM, N, PATH = 768, 20000, "/tmp/zvec_ro_repro"
schema = zvec.CollectionSchema(name="repro", vectors=zvec.VectorSchema("embedding", zvec.DataType.VECTOR_FP32, DIM))
col = zvec.create_and_open(PATH, schema)
rng = np.random.default_rng(0)
for i in range(0, N, 1000):
docs = [zvec.Doc(id=str(j), vectors={"embedding": rng.standard_normal(DIM).astype("float32")}) for j in range(i, min(i+1000, N))]
col.insert(docs)
col.optimize(); col.close()
ro = zvec.open(PATH, zvec.CollectionOption(read_only=True, enable_mmap=False))
vq = lambda: zvec.VectorQuery("embedding", vector=rng.standard_normal(DIM).astype("float32"), topk=10)
stop = threading.Event()
def worker():
while not stop.is_set():
try: ro.query(vq(), topk=10)
except Exception: pass
for t in [threading.Thread(target=worker, daemon=True) for _ in range(32)]: t.start()
time.sleep(120) # in our environment the process deadlocks within seconds~minutes
Logs / Stack Trace
=== py-spy dump of the deadlocked process ===
Every blocked thread ends at:
zvec/executor/query_executor.py:139 in _execute_single_query
docs = collection.Query(query)
... -> C extension -> futex_do_wait (kernel), never wakes
6 of the blocked threads were inside _execute_single_query; the rest were
callers waiting on the same C++ lock. Thread count keeps growing because each
new request spawns a thread that never returns.
=== Read-only query mutates index files ===
Listing the collection directory while ONLY read-only queries are running shows
the mtime of embedding.index.N.proxima files advancing:
# before queries
-rw-r--r-- embedding.index.3.proxima Sep 18 09:10:46
# after a few minutes of read-only queries only
-rw-r--r-- embedding.index.3.proxima Sep 18 09:11:02 <- mtime moved!
A read-only collection should never rewrite its index files. The writes appear
to contend with the internal proxima lock and produce the futex deadlock.
Operating System
Linux x86_64, WSL2 / Ubuntu 26.04, kernel 6.18.54
Build & Runtime Environment
zvec 0.7.0 (PyPI wheel), Python 3.14.4 (no custom build)
Additional Context
- I've checked
git status— no uncommitted submodule changes - I built with
CMAKE_BUILD_TYPE=Debug - This occurs with or without
COVERAGE=ON - The issue involves Python ↔ C++ integration (pybind11)
- 主要言語
- C++
- スター
- 16.3k
- フォーク
- 1k
- 平均マージ
- 2日 10時間
- マージ済み PR(30日)
- 32
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
alibaba/zvec のほかの issue
-
[Feature]: IVF_TIEREDQ index type, with a learned variable-bit codec (25–44% less index memory than `IVF_RABITQ` at equal recall)対応中かも @richyreachy が 7 日前に担当しました。 オープンfeature
メンテナーはふだん 1 日以内に返信
-
Support an opt-in portable x86 FastPFOR build without SSE4.1対応中かも @egolearner が 20 日前に担当しました。 オープン
alibaba/zvec#875 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Enhance]: Reduce vector index block fragmentation caused by frequent flushes対応中かも @feihongxu0824 が 22 日前に担当しました。 オープンenhancement
メンテナーはふだん 1 日以内に返信
-
[Performance]:High-selectivity range filter materializes a full bitmap — `bitset_set_list` ~49% CPU, dwarfing the ANN search対応中かも @zhourrr が 22 日前に担当しました。 オープンenhancement
alibaba/zvec#868 · コメント 13 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Performance] Warm-query latency on small collections with query() and query_internal_ids() in v0.8.0再び着手できるかも @egolearner が 33 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
deprecation internal refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
realloc(ptr, 0) on glibc leaves the freed block in the capture as a leak対応中かも @ADAMAMZAR が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
bloomberg/memray#1097 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
new-compilers request
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
compiler-explorer/compiler-explorer#9640 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
deepseek-ai/DeepEP#839 ·
メンテナーはふだん 6 日以内に返信