Skip to content

LSMVectorIndex.close() releases the build pool and then flushes, so a dirty index leaks a whole new ForkJoinPool past close() #6518

Closed

Description

@lvca

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() calls vectorIndex.clear() first, so flush() sees size() == 0 and 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 calls flush() and releaseBackgroundResources() 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

  1. Reorder close() to flush(); releaseBackgroundResources();, matching LocalDatabase.closeDurableParts() and the rationale already written there. Then the build that flush() may run has its pool alive, and the release afterwards shuts down the pool that build actually used.
  2. 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

  1. added this to the 26.9.1 milestone on Aug 20, 2026
  2. self-assigned this
    on Aug 20, 2026
  3. added
    in progress
    on Aug 20, 2026
  4. added a commit that references this issue on Aug 20, 2026
  5. lvca commented on Aug 27, 2026

    @lvca
    MemberAuthor

    Fixed on main by 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 does flush(); releaseBackgroundResources(); matching LocalDatabase.closeDurableParts(), and flush() guards against building a graph after resources are released (logs a WARNING and skips instead of leaking a new pool). Regression test: Issue6518CloseDoesNotLeakBuildPoolTest.

  6. added
    concurrency
    engine
    vector
    on Sep 2, 2026
  7. removed
    in progress
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyenginevector

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions