GH-5931: Shut down ExecutorService in CassandraVectorStore.close()#6019
Open
suryateja-g13 wants to merge 1 commit into
Open
GH-5931: Shut down ExecutorService in CassandraVectorStore.close()#6019suryateja-g13 wants to merge 1 commit into
suryateja-g13 wants to merge 1 commit into
Conversation
…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>
91f5585 to
6ea96f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
CassandraVectorStorecreates a fixed-sizeExecutorServicethread pool in its constructor but never shuts it down inclose(). 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
executorfield type fromExecutortoExecutorServicethis.executor.shutdownNow()at the start ofclose()so all threads are released promptlyTest
Added
closeShutsDownExecutortoCassandraVectorStoreITwhich usesReflectionTestUtilsto access the private executor field and asserts it is shut down afterclose()is called.Fixes GH-5931 (#5931)