Skip to content

GH-5931: Shut down ExecutorService in CassandraVectorStore.close()#6019

Open
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:GH-5931-cassandra-executor-thread-leak
Open

GH-5931: Shut down ExecutorService in CassandraVectorStore.close()#6019
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:GH-5931-cassandra-executor-thread-leak

Conversation

@suryateja-g13
Copy link
Copy Markdown

What

CassandraVectorStore creates a fixed-size ExecutorService thread pool in its constructor but never shuts it down in close(). This causes a thread leak — threads accumulate and are never reclaimed, which can exhaust resources in multi-tenant applications that dynamically create and destroy store instances.

Fix

  • Changed the executor field type from Executor to ExecutorService
  • Added this.executor.shutdownNow() at the start of close() so all threads are released promptly

Test

Added closeShutsDownExecutor to CassandraVectorStoreIT which uses ReflectionTestUtils to access the private executor field and asserts it is shut down after close() is called.

Fixes GH-5931 (#5931)

…tore.close()

The ExecutorService created in the constructor was never shut down when
close() was called, causing thread leaks in applications that dynamically
create and destroy CassandraVectorStore instances (e.g. multi-tenant
scenarios).

Changed the field type from Executor to ExecutorService and updated close()
to call shutdown() followed by awaitTermination(30s) before closing the
session. This allows in-flight CQL writes to complete gracefully before the
session is closed. If tasks do not finish within 30 seconds, shutdownNow()
is called to cancel remaining work.

Fixes spring-projectsGH-5931 (spring-projects#5931)

Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
@suryateja-g13 suryateja-g13 force-pushed the GH-5931-cassandra-executor-thread-leak branch from 91f5585 to 6ea96f7 Compare May 13, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CassandraVectorStore does not close ExecutorService causing thread leak

1 participant