Repository navigation
Description
VectorIndexCache: unbounded retryable-load loop (load storm under index rebuild churn)
Source: adversarial counterexample review of the 18 substantive commits in
4.2-devvsv4.2.8(static, code-level findings: the loop structure is provable directly from the code; no dynamic reproduction was run — recipe below). Introduced by162d3c37a6(backport of #32354);mainmay 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):
- The retry loop has no attempt cap, no backoff, and the top of the loop never checks
ctx.Err(). discardFailedLoad(:536-542) destroys this entry synchronously, which closes the entry'sdestroyedchannel.awaitDestroyed(:230-240) returnsctx.Err()in both select cases — so with an alive ctx anddestroyedalready 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()
}- The trigger is real:
errLoadGenerationSupersededis returned atpkg/fulltext2/search_cache.go:91,170andtail_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
- Cap consecutive retryable loads (2–3), add short backoff between rounds, and check
ctx.Err()at the top of the loop; - Add a deferred
recoverinLoad→ setSTATUS_ERRORand broadcast (or otherwise guarantee the panic path always seals the entry); - Make
c.donebuffered with capacity 1.
Activity
[-]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[/+][4.2] Fix vector index cache recovery lifecycle (#32404)
XuPeng-SH commentedon Nov 19, 2026
Closure evidence: fixed by #32404 (merged to 4.2-dev as c660611, 2026-11-09). All three reported problems are addressed:
searchnow limits each request to one cancellation-aware retry (pkg/vectorindex/cache/cache.go, "search limits each request to one retry"); covered byTestCacheRetryBudgetAndCanceledAdmission.TestCacheLoadPanicAndWaiterCancellation.Destroyblocking on the unbuffereddonechannel: shutdown is once-guarded and idempotent, and claimed entries are finished after the cleanup drain; covered byTestCacheConcurrentAndRepeatedDestroy.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
-racemode inpkg/vectorindex/cache.Reopen if a new unbounded-churn recursion appears.