Skip to content

bug(python): create_fts_index deadlocks with the ngram tokenizer on CPU-limited hosts (1CPU K8S pod) #3568

Closed
lance-format/lance
#7423

Description

@a-agmon

LanceDB version

v0.33.0

What happened?

create_fts_index(..., base_tokenizer="ngram", prefix_only=False) deadlocks permanently (the process sits at ~0% CPU with every thread asleep) once the input is large enough to produce more than one posting-list output batch, when the lance CPU runtime's blocking pool has only a single usable thread — i.e. on any host where num_cpus::get() <= 2 (small VMs, CPU-limited / pinned Kubernetes pods).

It is not a slow computation: during the hang, CPU is a sustained 0.0% and all threads are in futex_wait/epoll_wait. It reproduces with purely synthetic random text. Setting LANCE_CPU_THREADS=2 (or higher) fixes it.

Looks like source of the issue is in rust/lance-index/src/scalar/inverted/builder.rs
Deadlock cycle on a 1-thread blocking pool:

  1. Producer sends batch B1 => cap-1 channel is full.
  2. Producer's send_blocking(batch B2) parks the sole blocking thread.
  3. Consumer receives B1, calls write_record_batch => do_flush => spawn_cpu => needs the same pool => none free.
    Consumer can't complete the write, never drains the channel; producer never unparks. Permanent stall.

Environment

lancedb==0.33.0 (pins lance core =7.0.0), Python 3.12, pyarrow 24.0.0
Linux x86_64. Reproduces on a 1‑vCPU machine and on CPU‑limited pods. Local /tmp dataset (no object store involved).

Suggested fixes

Any of:

  • Use an async tx.send(batch).await instead of send_blocking in write_posting_lists, so the producer yields instead of parking a pool thread.
  • Ensure get_num_compute_intensive_cpus() returns at least 2 (the writer needs producer + consumer to make progress concurrently), and/or make CPU sizing cgroup-quota aware.
  • Run the producer and the consumer-encode on distinct pools, or decouple the channel capacity from the pool size.

Workaround

Set LANCE_CPU_THREADS=2 (or higher) in the environment. This fully resolves the hang without changing index semantics (keeps prefix_only=False).

Are there known steps to reproduce?

import os, time, random, pyarrow as pa, lancedb
random.seed(1234)
alpha=[chr(c) for c in range(0x05D0,0x05EA)]+list("abcdefghijklmnopqrstuvwxyz0123456789")
rows,total=[],0
while total<800_000:
    L=random.randint(50,300); s="".join(random.choice(alpha) for _ in range(L)); rows.append(s); total+=len(s)
db=lancedb.connect("/tmp/lance_repro")
try: db.drop_table("t")
except: pass
tb=db.create_table("t",pa.table({"search_text":pa.array(rows,type=pa.string())}),mode="overwrite")
t0=time.time()
tb.create_fts_index("search_text",replace=True,use_tantivy=False,base_tokenizer="ngram",
  ngram_min_length=3,ngram_max_length=3,prefix_only=False)
print("done %.2fs"%(time.time()-t0))

On a host with ≤ 2 visible CPUs: hangs indefinitely (done never prints).
LANCE_CPU_THREADS=2 python repro.py: completes in ~1s.

Activity

  1. added
    bug
    on Jun 22, 2026
  2. hiSandog commented on Jun 28, 2026

    @hiSandog

    This sounds like a good regression test for the runtime configuration, not just the tokenizer. A test that constrains the CPU/blocking pool to one usable worker and builds an ngram FTS index large enough to produce multiple posting-list output batches would pin down the deadlock boundary. That would also protect small Kubernetes pod deployments, where num_cpus can make behavior differ from developer machines.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions