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

@Fallback strategy seems not to work with Kotlin coroutines and additional exception in method signature #828

Closed
thjaeckle opened this issue May 17, 2023 · 1 comment · Fixed by #829
Assignees
Milestone

Comments

@thjaeckle
Copy link

Hi.
I am trying to adjust my Kotlin code to use "coroutines" while still defining a @Fallback method:

    @Incoming("lorawan")
    @Acknowledgment(Acknowledgment.Strategy.MANUAL)
    @Asynchronous
    @Retry(delay = 25, maxRetries = 5)
    @ExponentialBackoff
    @Fallback(fallbackMethod = "fallbackProcessor")
    suspend fun processor(kafkaMessage: Message<LoRaWanMessage>) {
       ...
    }

The following fallback method signature works as expected:

    suspend fun fallbackProcessor(kafkaMessage: Message<LoRaWanMessage>) {
       ...
    }

However, if I add an Exception like documented in the Fallback Methods with Exception Parameter
:

    suspend fun fallbackProcessor(kafkaMessage: Message<LoRaWanMessage>, ex: Exception) {
       ...
    }

I get a java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus error:

Caused by: jakarta.enterprise.inject.spi.DeploymentException: org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException: Invalid @Fallback on LoRaUplinkKafkaGateway.processor(org.eclipse.microprofile.reactive.messaging.Message, kotlin.coroutines.Continuation): can't find fallback method 'fallbackProcessor' with matching parameter types and return type
	at io.quarkus.smallrye.faulttolerance.runtime.SmallRyeFaultToleranceRecorder.createFaultToleranceOperation(SmallRyeFaultToleranceRecorder.java:44)
	at io.quarkus.deployment.steps.SmallRyeFaultToleranceProcessor$processFaultToleranceAnnotations1906679055.deploy_0(Unknown Source)
	at io.quarkus.deployment.steps.SmallRyeFaultToleranceProcessor$processFaultToleranceAnnotations1906679055.deploy(Unknown Source)
	... 68 more
Caused by: org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException: Invalid @Fallback on LoRaUplinkKafkaGateway.processor(org.eclipse.microprofile.reactive.messaging.Message, kotlin.coroutines.Continuation): can't find fallback method 'fallbackProcessor' with matching parameter types and return type
	at io.smallrye.faulttolerance.config.FallbackConfig.validate(FallbackConfig.java:42)
	at io.smallrye.faulttolerance.config.FaultToleranceOperation.validate(FaultToleranceOperation.java:365)
	at io.quarkus.smallrye.faulttolerance.runtime.SmallRyeFaultToleranceRecorder.createFaultToleranceOperation(SmallRyeFaultToleranceRecorder.java:28)
	... 70 more

I am again overseeing something obvious in the documentation?
io.smallrye:smallrye-fault-tolerance-kotlin is on the classpath.
I am using Quarkus version 3.0.3 and smallrye-fault-tolerance 6.2.2.

Without Kotlin coroutines the fallback method with additional Exception in the signature work as expected.

@Ladicek
Copy link
Contributor

Ladicek commented May 18, 2023

You're not missing anything, this is a bug. The problem is that the search for the fallback method expects that the exception parameter is the last one, which it isn't in case of Kotlin suspend functions.

The processor method has the following parameters in the JVM bytecode: (Message, Continuation). We append an exception type to that list when looking for the fallback method, so we expect to find a method with the following parameters: (Message, Continuation, Exception). Obviously, that's not what happens; the fallbackProcessor method has parameters (Message, Exception, Continuation).

Need to think about proper fix.

@Ladicek Ladicek self-assigned this May 18, 2023
@Ladicek Ladicek added this to the 6.2.3 milestone May 18, 2023
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 a pull request may close this issue.

2 participants