Skip to content

Fix BrokerPool shutdown hang causing CI timeouts#6167

Merged
line-o merged 1 commit intoeXist-db:developfrom
joewiz:bugfix/brokerpool-shutdown
Mar 24, 2026
Merged

Fix BrokerPool shutdown hang causing CI timeouts#6167
line-o merged 1 commit intoeXist-db:developfrom
joewiz:bugfix/brokerpool-shutdown

Conversation

@joewiz
Copy link
Copy Markdown
Member

@joewiz joewiz commented Mar 23, 2026

Summary

Fixes the root cause behind CI timeout failures across multiple PRs. The forked JVM hangs after BrokerPool.shutdown() completes because non-daemon threads and unbounded wait loops prevent JVM exit.

Three-part fix

  1. Daemon StatusReporter threads — The startup-status-reporter and shutdown-status-reporter threads are monitoring-only and must not prevent JVM exit. Added newInstanceDaemonThread() to ThreadUtils and used it for both StatusReporter threads.

  2. Bounded wait loops with shutdown checks — Four wait loops in BrokerPool swallowed InterruptedException with //nothing to be done! comments and used unbounded wait(). Now all four have 1-second poll timeouts, isShuttingDown() checks, and proper interrupt handling:

    • get() service mode wait — breaks on shutdown or interrupt
    • get() broker availability wait — throws EXistException on shutdown/interrupt
    • enterServiceMode() wait — breaks on shutdown or interrupt
    • shutdown() active brokers wait — re-sets interrupt flag and breaks
  3. Thread group interrupt on shutdown — At the end of shutdown, instanceThreadGroup.interrupt() wakes any lingering threads so they can exit cleanly.

Before/after

Previously, 4 test classes required exclusion or timeout workarounds (DeadlockIT, RemoveCollectionIT, CollectionLocksTest, MoveResourceTest). Now all 4 complete cleanly: 6533 unit tests + 9 integration tests, 0 failures, clean JVM exit in ~12 minutes total.

Related

Test plan

  • Full mvn test -pl exist-core — 6533 tests, 0 failures, BUILD SUCCESS, clean exit (4 min)
  • Full mvn verify -pl exist-core integration tests — 9 tests including previously-excluded DeadlockIT and RemoveCollectionIT, 0 failures, BUILD SUCCESS, clean exit (8 min)
  • CI passes on all platforms (ubuntu, macOS, windows)

🤖 Generated with Claude Code

Three targeted fixes prevent the forked JVM from hanging after
BrokerPool.shutdown() completes:

1. StatusReporter threads are now daemon threads. The startup and
   shutdown status reporter threads are monitoring-only and must not
   prevent JVM exit. Added newInstanceDaemonThread() to ThreadUtils.

2. Four wait loops in BrokerPool that swallowed InterruptedException
   and used unbounded wait() now have 1-second poll timeouts,
   isShuttingDown() checks, and proper interrupt handling:
   - get() service mode wait: breaks on shutdown or interrupt
   - get() broker availability wait: throws EXistException on shutdown
   - enterServiceMode() wait: breaks on shutdown or interrupt
   - shutdown() active brokers wait: re-sets interrupt flag and breaks

3. At end of shutdown, instanceThreadGroup.interrupt() wakes any
   lingering threads in the instance's thread group.

Previously, 4 test classes required exclusion or timeout workarounds
(DeadlockIT, RemoveCollectionIT, CollectionLocksTest, MoveResourceTest).
Now all complete cleanly: 6533 unit tests + 9 integration tests,
0 failures, clean JVM exit.

Affects PRs with CI timeout workarounds: eXist-db#6112, eXist-db#6139, eXist-db#6138
Related: eXist-db#3685 (FragmentsTest deadlock)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joewiz joewiz requested a review from a team as a code owner March 23, 2026 15:46
Copy link
Copy Markdown
Member

@line-o line-o left a comment

Choose a reason for hiding this comment

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

LGTM
side note: the formatting is slightly off in the if-condition

@line-o line-o merged commit 75eaa77 into eXist-db:develop Mar 24, 2026
9 checks passed
joewiz added a commit to joewiz/exist that referenced this pull request Mar 24, 2026
Pick up BrokerPool shutdown fix (eXist-db#6167) and @line-o's function type
checking refactoring. Resolved 11 merge conflicts.

Known regression: 12 XQSuite map ordering tests fail (QT4-only,
not in QT3/XQ31). @line-o's MapType refactoring removed the
keyOrder tracking that our XQ4 ordered map implementation used.
The ordered map support needs to be re-implemented on top of the
new MapType API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
joewiz added a commit to joewiz/exist that referenced this pull request Mar 25, 2026
BlobStoreImpl's PersistentWriter and BlobVacuum threads were created as
non-daemon threads, which prevents JVM exit if BrokerPool shutdown fails
to join them cleanly. This caused ~20% of CI runs to hang indefinitely
after tests completed.

Mark both threads as daemon threads so they cannot block JVM shutdown.
The threads still participate in normal shutdown via poison pill
(PersistentWriter) and interrupt (BlobVacuum), but now the JVM can exit
even if those shutdown paths fail.

Also add a forkedProcessExitTimeoutInSeconds safety net to the surefire
configuration, and a regression test that verifies no non-daemon eXist
threads survive BrokerPool shutdown.

Follow-up to PR eXist-db#6167 which fixed the same issue for StatusReporter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

3 participants