fix(spi): make ConnectionPool cleanup thread a named daemon - #2386
Merged
openai0229 merged 4 commits intoAug 3, 2026
Merged
Conversation
…d#2383) The static initializer started a permanent cleanup loop as a user (non-daemon) thread, so the JVM could not exit cleanly once the pool class was loaded — the process hung on shutdown in desktop/embedded/test runs. Mark the thread as a daemon and name it 'chat2db-conn-pool-cleanup' so it does not block JVM exit and is attributable in thread dumps. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: liuhy <liuhongyu@apache.org>
There was a problem hiding this comment.
Pull request overview
Findings (severity order)
chat2db-community-server/chat2db-community-spi/src/main/java/ai/chat2db/spi/sql/ConnectionPool.java:34-49(SPI/runtime shutdown behavior): the fix isn’t covered by a regression test asserting the cleanup thread is namedchat2db-conn-pool-cleanupand runs as a daemon, so a future refactor could accidentally reintroduce the non-daemon shutdown hang.
This PR fixes a JVM shutdown hang by ensuring ConnectionPool’s permanent cleanup loop runs on a named daemon thread, preventing it from keeping the process alive after shutdown and making it easier to identify in thread dumps/monitoring.
Changes:
- Replace the anonymous
new Thread(...).start()with aThread cleanupThreadvariable. - Name the thread
chat2db-conn-pool-cleanupand mark it as daemon before starting.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
openai0229
approved these changes
Aug 3, 2026
openai0229
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the named daemon cleanup-thread change and the regression test after syncing with the latest main. ConnectionPoolTest executes 10 tests successfully, and the test explicitly initializes ConnectionPool before locating the thread.
This was referenced Aug 4, 2026
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
ConnectionPool's static initializer started a permanent cleanup loop as a non-daemon thread, so the JVM could not exit cleanly once the pool class was loaded — the process hung on shutdown in desktop/embedded/test runs.Location
chat2db-community-spi/src/main/java/ai/chat2db/spi/sql/ConnectionPool.java:34-45Fix
Mark the thread as a daemon and name it
chat2db-conn-pool-cleanupso it does not block JVM exit and is attributable in thread dumps/monitoring. The loop body is unchanged.Verification
Thread.setDaemon(true)must be called beforestart()(it is).ConnectionPoolis initialized), then trigger application shutdown — the process must exit without hanging.Fixes #2383
🤖 Generated with Claude Code