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

AOP - Using Retryable and Recoverable with a suspend function fails #7101

Closed
tmapes opened this issue Mar 18, 2022 · 2 comments
Closed

AOP - Using Retryable and Recoverable with a suspend function fails #7101

tmapes opened this issue Mar 18, 2022 · 2 comments
Labels
type: bug Something isn't working

Comments

@tmapes
Copy link

tmapes commented Mar 18, 2022

Expected Behavior

A suspend function annotated with both @Retryable and @Recoverable should retry as many times as configured in the Retryable annotation before triggering the Recoverable Fallback.

Actual Behaviour

During execution, a ClassCastException is raised during the RecoveryInterceptor that causes the Fallback to be executed during execution of the declared function.

This causes the calling function to get the 'Fallback' output before the retries are completed.

This also leads to the retries happening in the background, despite the fact that the Fallback has already fired.

The below stacktrace is logged:

java.lang.ClassCastException: class kotlin.Unit cannot be cast to class java.util.concurrent.CompletableFuture (kotlin.Unit is in unnamed module of loader 'app'; java.util.concurrent.CompletableFuture is in module java.base of loader 'bootstrap')
	at io.micronaut.retry.intercept.RecoveryInterceptor.lambda$fallbackForFuture$3(RecoveryInterceptor.java:167)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
	at io.micronaut.aop.util.CompletableFutureContinuation.resumeWith(CompletableFutureContinuation.kt:51)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

Steps To Reproduce

  • Declare a suspend function and annotate it with both Recoverable and Retryable.
  • Implement a sufficient Fallback implementation for this function
  • Throw an exception inside the suspend function that should trigger a retry
  • The callers invocation of this suspend function is then 'completed' with the Fallback's return value while retries continue in the background.
    • My example repo has the suspend function return Unit however the same issue happens when you return a value, I tested with Boolean

Environment Information

OS - macOS 12.2.1 (x86_64)
JVM - 11.0.11

Example Application

https://github.com/tmapes/micronaut-suspend-retry-recover

Version

3.3.4

@hollingsworthd hollingsworthd self-assigned this May 12, 2022
@hollingsworthd
Copy link

Thanks for the bug report and branch to reproduce this.

I reproduced this bug and investigated, but I am not a Kotlin expert -- @sdelamo should someone else take this on? Un-assigning myself for the moment.

@hollingsworthd hollingsworthd added the type: bug Something isn't working label May 13, 2022
@hollingsworthd hollingsworthd removed their assignment May 13, 2022
graemerocher pushed a commit that referenced this issue Feb 27, 2023
@tmapes
Copy link
Author

tmapes commented Mar 4, 2023

Confirmed fixed in https://github.com/micronaut-projects/micronaut-core/releases/tag/v3.8.6, thanks folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants