Repository navigation
Description
LSMVectorIndex.close() runs its two steps in the opposite order to the one LocalDatabase uses, and the inversion is not cosmetic: on a dirty index it leaks a live ForkJoinPool.
public void close() {
releaseBackgroundResources(); // shuts the graph-build pool down, sets valid = false
flush(); // ...then asks for a graph build, which needs that pool
}LocalDatabase.closeDurableParts() does the reverse, and says why:
Deliberately AFTER the flush above (an index whose graceful shutdown is a graph build needs its build pool alive for it)
What actually happens
getOrCreateGraphBuildPool() treats a shut-down pool as a pool to replace:
if (pool != null && !pool.isShutdown() && pool.getParallelism() == wanted)
return pool;So flush() builds a brand new pool after releaseBackgroundResources() has just torn the old one down, runs the rebuild on it, and nothing ever shuts the replacement down - close() has already done its releasing.
Measured on a 200-vector index made dirty with one extra insert, calling index.close() directly:
before close: graphState=2 (MUTABLE) rebuilds=1 valid=true
after close: graphState=1 (IMMUTABLE) rebuilds=2 valid=false
pool after close: shutdown=false terminated=false poolSize=17 parallelism=17
live ForkJoinPool threads: 17
The rebuild ran and the graph was persisted - so the failure is silent, and correctness-wise the close even "worked". It just left 17 worker threads running on an index that is closed and marked invalid. That is the exact failure #5418 was filed for ("the vector index inactivity rebuild timer outlived Database.close()"), reintroduced through a different door.
Note also that nothing on the build path checks validity: buildGraphFromScratchExclusively() has no isValid()/checkIsValid() guard, so an index with valid = false builds a full graph quite happily.
Reachability
Latent today, which is why it has not bitten:
drop()->close()is safe by accident:drop()callsvectorIndex.clear()first, soflush()seessize() == 0and skips the build entirely.TypeIndex.close()->index.close()has no production caller I can find.- The database close path does not use
close()at all -closeDurableParts()deliberately callsflush()andreleaseBackgroundResources()separately, in the correct order.
So it needs someone to call close() on a vector index that still has vectors and pending mutations. close() is public API on IndexInternal, and the ordering is one refactor away from mattering.
Suggested fix
- Reorder
close()toflush(); releaseBackgroundResources();, matchingLocalDatabase.closeDurableParts()and the rationale already written there. Then the build thatflush()may run has its pool alive, and the release afterwards shuts down the pool that build actually used. - Guard
flush()so it cannot start a build once background resources are released. Defence in depth for the same trap arriving from a future caller: skipping the persist costs a rebuild on the next open, whereas leaking the pool costs threads for the lifetime of the process. Worth a WARNING rather than a silent skip, so an ordering regression is loud.
Found while fixing #6503, where the same ordering asymmetry (closeDurableParts() flushes before releasing, close() releases before flushing) had already caused one wrong assumption - see the searcher-pool pinning bug in PR #6513.
Activity
fix(#6518): close() released the build pool before flushing, so a dir…
lvca commentedon Aug 27, 2026
Fixed on
mainby commit 304c823 ("fix(#6518): close() released the build pool before flushing, so a dirty vector index leaked a new one"), pushed 2026-08-20.LSMVectorIndex.close()now doesflush(); releaseBackgroundResources();matchingLocalDatabase.closeDurableParts(), andflush()guards against building a graph after resources are released (logs a WARNING and skips instead of leaking a new pool). Regression test:Issue6518CloseDoesNotLeakBuildPoolTest.