DbSchedulerDeadlineManager Race Condition?

Hello,
See this error… I will confirm, but I had to restart an app that had shutdown for some unknown reason. There were a few unprocessed deadlines when I attempted to start the app and I think I got this error because DB Scheduler tried to execute it before Axon was ready. When the app had enough time to boot up before the next deadline was scheduled, there were no issues. Pleasea advise. Thanks!

2024-11-22T13:32:35.625-08:00  WARN 3366406 --- [pool-3-thread-2] c.g.kagkarlsson.scheduler.Scheduler      : Unhandled exception during execution of task with name 'AxonDeadline'. Treating as failure.

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.axonframework.deadline.dbscheduler.DbSchedulerDeadlineManager' available
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:341) ~[spring-beans-6.0.15.jar!/:6.0.15]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332) ~[spring-beans-6.0.15.jar!/:6.0.15]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1184) ~[spring-context-6.0.15.jar!/:6.0.15]
        at org.axonframework.springboot.autoconfig.AxonDbSchedulerAutoConfiguration.lambda$dbSchedulerDeadlineDetailsTask$1(AxonDbSchedulerAutoConfiguration.java:71) ~[axon-spring-boot-autoconfigure-4.9.1.jar!/:4.9.1]
        at org.axonframework.deadline.dbscheduler.DbSchedulerDeadlineManager.lambda$binaryTask$1(DbSchedulerDeadlineManager.java:204) ~[axon-messaging-4.9.1.jar!/:4.9.1]
        at com.github.kagkarlsson.scheduler.task.helper.Tasks$OneTimeTaskBuilder$1.executeOnce(Tasks.java:257) ~[db-scheduler-13.0.0.jar!/:na]
        at com.github.kagkarlsson.scheduler.task.helper.OneTimeTask.execute(OneTimeTask.java:59) ~[db-scheduler-13.0.0.jar!/:na]
        at com.github.kagkarlsson.scheduler.ExecutePicked.executePickedExecution(ExecutePicked.java:95) ~[db-scheduler-13.0.0.jar!/:na]
        at com.github.kagkarlsson.scheduler.ExecutePicked.run(ExecutePicked.java:74) ~[db-scheduler-13.0.0.jar!/:na]
        at com.github.kagkarlsson.scheduler.FetchCandidates.lambda$run$1(FetchCandidates.java:110) ~[db-scheduler-13.0.0.jar!/:na]
        at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
        at com.github.kagkarlsson.scheduler.FetchCandidates.lambda$run$2(FetchCandidates.java:97) ~[db-scheduler-13.0.0.jar!/:na]
        at com.github.kagkarlsson.scheduler.Executor.lambda$addToQueue$0(Executor.java:53) ~[db-scheduler-13.0.0.jar!/:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
        at java.base/java.lang.Thread.run(Thread.java:840) ~[na:na]

It easily becomes a chicken/egg problem. It’s likely best to add a delay to db-scheduler, but I couldn’t find something like that. So maybe you could greate an issue and/or pr on db-scheduler? The raakt should be retried, so it’s just a little annoying currently I guess?

Yeah, I did look at the code and the phrase “chicken/egg” came to mind as well. I get it though. The Axon component depends on the presence of the scheduler, but the scheduler wants to execute the job before the Axon component is ready. I can understand the first failure. But, I’m curious why it doesn’t resolve itself the next time it executes?I will see what I can do and follow-up. Thanks!

Well, I replicated the issue locally and fortunately, the solution was very simple. Just have to add this to the application properties file:

db-scheduler.delayStartupUntilContextReady = true
1 Like