Skip to content

VectorIndexCache: unbounded retryable-load loop in Search/SearchInto under index rebuild churn; Load panic wedges loading; unbuffered c.done blocks repeat Destroy #32403

Closed

Description

@XuPeng-SH

VectorIndexCache: unbounded retryable-load loop (load storm under index rebuild churn)

Source: adversarial counterexample review of the 18 substantive commits in 4.2-dev vs v4.2.8 (static, code-level findings: the loop structure is provable directly from the code; no dynamic reproduction was run — recipe below). Introduced by 162d3c37a6 (backport of #32354); main may carry the same loop if it shares that PR's origin — unverified.

Problem 1 (major): the Search / SearchInto retryable-load loop spins without bound

pkg/vectorindex/cache/cache.go:662-668 (Search) and :718-724 (SearchInto):

if IsRetryableLoadError(err) {
    c.discardFailedLoad(key, algo)
    if waitErr := algo.awaitDestroyed(searchContext(sqlproc)); waitErr != nil {
        return nil, nil, waitErr
    }
    continue
}

Counterexample chain (each step confirmed by reading the code):

  1. The retry loop has no attempt cap, no backoff, and the top of the loop never checks ctx.Err().
  2. discardFailedLoad (:536-542) destroys this entry synchronously, which closes the entry's destroyed channel.
  3. awaitDestroyed (:230-240) returns ctx.Err() in both select cases — so with an alive ctx and destroyed already closed it returns nil with zero wait:
select {
case <-s.destroyed: return ctx.Err() // ctx.Err() == nil → immediate nil return
case <-ctx.Done():     return ctx.Err()
}
  1. The trigger is real: errLoadGenerationSuperseded is returned at pkg/fulltext2/search_cache.go:91,170 and tail_pool.go:441,455. During index rebuild churn (repeated generation supersede), the current generation's load keeps being invalidated.

Consequence: while churn persists, a single request becomes "full cache Load → superseded → discard & reload → superseded → …" — a load storm that only ends when the statement times out. Each round pays the real cost of the entry's Load SQL (for fulltext2, the LoadAllBases reads) and in turn amplifies the rebuild's own churn.

Problem 2 (minor): a Load panic leaves the entry wedged in loading; searchers park forever

cache.go:299-332: Load's defer only unlocks and broadcasts; there is no recover, so a panic never gets to set STATUS_ERROR. Subsequent Search waiters sit in for s.Status.Load() == 0 { s.Cond.Wait() } (:391-395) with nobody left to wake them → goroutine leak and hung queries until process exit.

Problem 3 (minor): unbuffered c.done send may block a second Destroy forever

cache.go:477: c.done <- true is unbuffered; once serve has exited (:622-627), a second Destroy's send has no receiver and blocks forever. No concurrent Destroy caller exists on the current tree, so this is latent; make(chan bool, 1) fixes it.

Reproduction recipe (no unit tests / BVT needed)

A ~30-line scratch program: implement a fake VectorIndexSearchIf whose Load always returns errLoadGenerationSuperseded, call VectorIndexCache.Search directly, and count Load invocations — expect linear growth over time until the ctx is cancelled. Problem 2 can be injected via a Load that panics; problem 3 via two goroutines racing Destroy.

Suggested fixes

  1. Cap consecutive retryable loads (2–3), add short backoff between rounds, and check ctx.Err() at the top of the loop;
  2. Add a deferred recover in Load → set STATUS_ERROR and broadcast (or otherwise guarantee the panic path always seals the entry);
  3. Make c.done buffered with capacity 1.

Activity

  1. added
    kind/bug
    on Nov 9, 2026
  2. changed the title [-]VectorIndexCache Search/SearchInto 可重试加载循环无上限:索引重建 churn 下形成 load 风暴(另含 Load panic 卡 loading、c.done 二次 Destroy 阻塞)[/-] [+]VectorIndexCache: unbounded retryable-load loop in Search/SearchInto under index rebuild churn; Load panic wedges loading; unbuffered c.done blocks repeat Destroy[/+] on Nov 9, 2026
  3. self-assigned this
    on Nov 9, 2026
  4. added a commit that references this issue on Nov 9, 2026
    c660611
  5. XuPeng-SH commented on Nov 19, 2026

    @XuPeng-SH
    ContributorAuthor

    Closure evidence: fixed by #32404 (merged to 4.2-dev as c660611, 2026-11-09). All three reported problems are addressed:

    1. Unbounded retryable-load loop: search now limits each request to one cancellation-aware retry (pkg/vectorindex/cache/cache.go, "search limits each request to one retry"); covered by TestCacheRetryBudgetAndCanceledAdmission.
    2. Load panic wedging the entry: load panics are sealed and published to waiters, so searchers no longer park forever; covered by TestCacheLoadPanicAndWaiterCancellation.
    3. Repeated Destroy blocking on the unbuffered done channel: shutdown is once-guarded and idempotent, and claimed entries are finished after the cleanup drain; covered by TestCacheConcurrentAndRepeatedDestroy.

    Verification on 4.2-dev head 71e2233, linux/amd64, Go 1.27.1, via the repository CGo test wrapper: the three targeted tests pass in both normal and -race mode in pkg/vectorindex/cache.

    Reopen if a new unbounded-churn recursion appears.

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

Metadata

Metadata

Assignees

Labels

area/stabilitykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions