Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quarkus-quartz: programmatic scheduling of async tasks with jdbc-cmt breaks application startup #41361

Closed
jacopo-cavallarin opened this issue Jun 21, 2024 · 2 comments · Fixed by #41370
Labels
area/scheduler kind/bug Something isn't working
Milestone

Comments

@jacopo-cavallarin
Copy link

Describe the bug

I am using quarkus-quartz to schedule an asynchronous job programmatically using io.quarkus.scheduler.Scheduler and the jdbc-cmt store type.

After scheduling the job for the first time, when we restart the application it fails to create the Scheduler. The root cause is this:

Caused by: java.lang.ClassCastException: class io.test.ProgrammaticAsyncJob_ClientProxy cannot be cast to class java.util.function.Consumer (io.test.ProgrammaticAsyncJob_ClientProxy is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @4a0a1e66; java.util.function.Consumer is in module java.base of loader 'bootstrap')
        at io.quarkus.quartz.runtime.QuartzSchedulerImpl$SerializedExecutionMetadata.task(QuartzSchedulerImpl.java:1305)
        at io.quarkus.quartz.runtime.QuartzSchedulerImpl.createJobDefinitionQuartzTrigger(QuartzSchedulerImpl.java:928)
        at io.quarkus.quartz.runtime.QuartzSchedulerImpl.<init>(QuartzSchedulerImpl.java:312)
        ... 29 more

It looks like quarkus is incorrectly assuming that the scheduled job is synchronous, as it's casting it to a Consumer instead of a Function.

Looking at the source code of QuartzSchedulerImpl, it seems this line is the problem: it should be using EXECUTION_METADATA_ASYNC_TASK_CLASS as key instead of EXECUTION_METADATA_TASK_CLASS.

In fact, on this line it's attempting to load the async task class using the EXECUTION_METADATA_ASYNC_TASK_CLASS key.

This seems to be the reason why quarkus is wrongly treating async tasks as synchronous when loading them from the database.

Expected behavior

The application should start without errors while an asynchronous job is scheduled in quartz's jdbc store.

Actual behavior

The application fails to start due to a ClassCastException:

Caused by: java.lang.ClassCastException: class io.test.ProgrammaticAsyncJob_ClientProxy cannot be cast to class java.util.function.Consumer (io.test.ProgrammaticAsyncJob_ClientProxy is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @4a0a1e66; java.util.function.Consumer is in module java.base of loader 'bootstrap')
        at io.quarkus.quartz.runtime.QuartzSchedulerImpl$SerializedExecutionMetadata.task(QuartzSchedulerImpl.java:1305)
        at io.quarkus.quartz.runtime.QuartzSchedulerImpl.createJobDefinitionQuartzTrigger(QuartzSchedulerImpl.java:928)
        at io.quarkus.quartz.runtime.QuartzSchedulerImpl.<init>(QuartzSchedulerImpl.java:312)
        ... 29 more

How to Reproduce?

Reproducer: https://github.com/jacopo-cavallarin/quarkus-quartz-bug-reproducer

Follow the README included in the reproducer.

Output of uname -a or ver

Darwin M0-055116363 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64

Output of java -version

openjdk version "22" 2024-03-19 OpenJDK Runtime Environment Temurin-22+36 (build 22+36) OpenJDK 64-Bit Server VM Temurin-22+36 (build 22+36, mixed mode)

Quarkus version or git rev

3.11.3

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.7 (8b094c9513efc1b9ce2d952b3b9c8eaedaf8cbf0) Maven home: /Users/jacopocavallarin/.m2/wrapper/dists/apache-maven-3.9.7-bin/33482774/apache-maven-3.9.7 Java version: 22, vendor: Eclipse Adoptium, runtime: /Users/jacopocavallarin/.sdkman/candidates/java/22-tem Default locale: en_IT, platform encoding: UTF-8 OS name: "mac os x", version: "14.5", arch: "aarch64", family: "mac"

Additional information

No response

@jacopo-cavallarin jacopo-cavallarin added the kind/bug Something isn't working label Jun 21, 2024
@jacopo-cavallarin jacopo-cavallarin changed the title quarkus-quartz: programmatic scheduling of async tasks with jdbc-cmt breaks when retrieving the scheduled job quarkus-quartz: programmatic scheduling of async tasks with jdbc-cmt breaks application startup Jun 21, 2024
@melloware

This comment was marked as outdated.

@melloware
Copy link
Contributor

@jacopo-cavallarin i submitted a PR please review

@quarkus-bot quarkus-bot bot added this to the 3.13 - main milestone Jun 24, 2024
@gsmet gsmet modified the milestones: 3.13 - main, 3.12.1 Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scheduler kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants