Skip to content

fix(spi): make ConnectionPool cleanup thread a named daemon - #2386

Merged
openai0229 merged 4 commits into
OtterMind:mainfrom
Aias00:fix/connectionpool-daemon-thread-2383
Aug 3, 2026
Merged

openai0229 merged 4 commits into
OtterMind:mainfrom
Aias00:fix/connectionpool-daemon-thread-2383

Conversation

@Aias00

@Aias00 Aias00 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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-45

Fix

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/monitoring. The loop body is unchanged.

Verification

  • Thread.setDaemon(true) must be called before start() (it is).
  • A daemon thread does not keep the JVM alive; the periodic cleanup still runs while the JVM is up.
  • Recommended manual check: load a datasource (so ConnectionPool is initialized), then trigger application shutdown — the process must exit without hanging.

Fixes #2383

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings August 3, 2026 06:22
@Aias00
Aias00 requested a review from openai0229 as a code owner August 3, 2026 06:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 named chat2db-conn-pool-cleanup and 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 a Thread cleanupThread variable.
  • Name the thread chat2db-conn-pool-cleanup and mark it as daemon before starting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@openai0229
openai0229 merged commit 39cc45f into OtterMind:main Aug 3, 2026
18 of 19 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(spi): ConnectionPool cleanup thread is non-daemon, blocking JVM shutdown

3 participants