-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Spring AOP is not compatible with Kotlin Coroutines #22462
Comments
Seems to be a pre-requisite for #23575. Good candidate for Spring Framework 5.3. |
I need this feature badly :) |
Hi, also highly requested! |
Yeah, that would help a lot! |
Need this feature too ! |
Hi, I would love to see this feature implemented. |
Sadly stumbled upon this bug :( I would need that badly |
Hey, here is an update on that topic. I have added Those Spring Data and Spring Security supports are possible without any change on Spring AOP, and Coroutines support requires to be added at a Reactive-aware level which is not the case of Spring AOP if I am not mistakes, so I am not sure anymore this issue is relevant. With this progresses in mind, please share your use cases requiring an update on Spring AOP if any. |
I would ask if there is chance to fix it at all? Issue is really old and there isn't any visible progress here. |
This is a tricky one from a design perspective, but let see if we can move forward. |
any updates? seems to block a lot of other issues downstream |
Hey, RoberHeim.
val ProceedingJoinPoint.coroutineContinuation: Continuation<Any?>
get() = this.args.last() as Continuation<Any?>
val ProceedingJoinPoint.coroutineArgs: Array<Any?>
get() = this.args.sliceArray(0 until this.args.size - 1)
suspend fun ProceedingJoinPoint.proceedCoroutine(
args: Array<Any?> = this.coroutineArgs
): Any? = suspendCoroutineUninterceptedOrReturn { continuation ->
this.proceed(args + continuation)
}
fun ProceedingJoinPoint.runCoroutine(
block: suspend () -> Any?
): Any? =
block.startCoroutineUninterceptedOrReturn(this.coroutineContinuation)
@Pointcut("args(.., kotlin.coroutines.Continuation)")
fun suspendFunctionPointCut() {
}
@Around("YourCustomPointCut() && suspendFunctionPointCut()")
fun handleGenericSystemErrors(joinPoint: ProceedingJoinPoint): Any? {
return joinPoint.runCoroutine {
val result = joinPoint.proceedCoroutine()!!
return@runCoroutine result
}
} |
@jun-wu-tw the problem is not that we need it in our code base, but it must be integrated in spring itself to solve downstream issues: |
After working on the Spring Security repro created by @jzheaux, I may have found a potential way to handle this. I managed to fix the repro with some changes on Spring Framework side that you can see in this draft commit. In a nutshell, at That way, proxified suspending functions return their It is possible to test this Spring Framework branch by cloning it, running As a consequence, I tentatively plan resolving this issue in Spring Framework @jhoeller @rstoyanchev @poutsma @jzheaux Please let me know if you have any concern about the proposed solution. |
Looks like we are going to have to do something more evolved in order to support non reflective use cases and make this less intrusive from the caller perspective. |
This commit adds support for Kotlin Coroutines to Spring AOP by leveraging CoroutinesUtils#invokeSuspendingFunction in AopUtils#invokeJoinpointUsingReflection to convert it to the equivalent Mono return value, like in other parts of Spring Framework. That allows MethodInterceptor with Reactive support to process related return values. CglibAopProxy#processReturnType and JdkDynamicAopProxy#invoke takes care of the conversion from the Publisher return value to Kotlin Coroutines if needed. Reactive transactional and HTTP service interface support have been refined to leverage those new generic capabilities. Closes spring-projectsgh-22462
Initial support pushed, please test Spring Framework @jzheaux Please let me know how it goes on Spring Security after you refine the support to avoid the multiple subscription issues we discussed on your repro. @mp911de @rstoyanchev I refined reactive transactional and HTTP service interface support to leverage those generic capabilities, tests are green but please ping me if you see related reports on Coroutines support. |
@jun-wu-tw sir, you saved the day, thank you so much |
The text was updated successfully, but these errors were encountered: