E534 Fix #4244: Properly shutdown Axon janitor thread on Spring context close by wadhwaroh-lang · Pull Request #4269 · AxonFramework/AxonFramework · GitHub
[go: up one dir, main page]

Skip to content

Fix #4244: Properly shutdown Axon janitor thread on Spring context close#4269

Open
wadhwaroh-lang wants to merge 3 commits intoAxonFramework:mainfrom
wadhwaroh-lang:fix/janitor-thread-shutdown-4244
Open

Fix #4244: Properly shutdown Axon janitor thread on Spring context close#4269
wadhwaroh-lang wants to merge 3 commits intoAxonFramework:mainfrom
wadhwaroh-lang:fix/janitor-thread-shutdown-4244

Conversation

@wadhwaroh-lang
Copy link

Description

Fixes #4244: Ensure the Axon framework's janitor thread is properly shut down when the Spring context closes.

Problem

The janitor ScheduledExecutorService introduced in version 4.11 was not being shut down during Spring context shutdown. Since the janitor thread is a non-daemon thread, it prevented the JVM from exiting gracefully.

Solution

Implemented AxonTaskJanitorShutdownHandler - a Spring SmartLifecycle bean that:

  1. Calls shutdown() on the AxonTaskJanitor.INSTANCE executor service
  2. Waits up to 5 seconds for graceful termination
  3. Forces shutdown via shutdownNow() if termination times out
  4. Executes at the very end of the shutdown process (phase = Integer.MAX_VALUE - 100)

Changes

  • ✅ Added AxonTaskJanitorShutdownHandler implementing SmartLifecycle
  • ✅ Registered handler bean in AxonTimeoutAutoConfiguration
  • ✅ Added comprehensive unit tests

Testing

  • Unit tests verify shutdown handler creation and lifecycle behavior
  • Tested that janitor thread is properly terminated on context close

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Implements a Spring lifecycle handler to manage the shutdown of the Axon janitor executor service, ensuring proper termination during application shutdown.
Add tests for AxonTaskJanitorShutdownHandler functionality
Add bean creation method for AxonTaskJanitorShutdownHandler to ensure proper shutdown of the janitor executor service during Spring context closure.
@wadhwaroh-lang wadhwaroh-lang requested a review from a team as a code owner March 11, 2026 00:43
@wadhwaroh-lang wadhwaroh-lang requested review from corradom, hatzlj and hjohn and removed request for a team March 11, 2026 00:43
@wadhwaroh-lang
Copy link
Author

@AxonFramework/AxonFramework

Please consider labeling this PR with below( as I don't have permissions yet) :

Thanks!

@hatzlj
Copy link
Contributor
hatzlj commented Mar 11, 2026

Thanks to bother to create a PR for this issue @wadhwaroh-lang, we'll be sure to have a look on this and align it with our efforts on 5.1.0 and 4.13.1.
Since the original issue was pointed towards Framework 4 it would be great if you could point your PR towards our 4.13.x patch branch and we'll make sure to propagate the fix to 5 accordingly once it's done. However, if that's not possible for you for any reason it's also fine and we'll work around it.

@hatzlj hatzlj added the Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. label Mar 11, 2026
@hatzlj hatzlj added this to the Release 4.13.1 milestone Mar 11, 2026
@hatzlj hatzlj added the Type: Bug Use to signal issues that describe a bug within the system. label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Type: Bug Use to signal issues that describe a bug within the system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spring context shutdown does not stop Axon janitor thread

2 participants

0