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

Spring coroutines AOP is not compatible with @Cacheable #33210

Closed
malaquf opened this issue Jul 12, 2024 · 4 comments
Closed

Spring coroutines AOP is not compatible with @Cacheable #33210

malaquf opened this issue Jul 12, 2024 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support type: bug A general bug
Milestone

Comments

@malaquf
Copy link

malaquf commented Jul 12, 2024

Affects: 6.1.8


When combined with other aspects on a suspend function like in the following example, the interceptor does not handle the aspect chain properly and aspects like TimedAspect are not executed.

@Timed("MyService.doSomething")
@Cacheable("something")
suspend fun getSomething() {
	...
}

The TimedAspect is executed if the annotated function is not a suspend function.

I tried to run it with @EnableCaching(mode = AdviceMode.ASPECTJ) for testing it but I get the following error during startup:


Caused by: java.lang.IllegalStateException: Expecting to find 3 arguments to bind by name in advice, but actually found 2 arguments.
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.bindExplicitArguments(AbstractAspectJAdvice.java:472)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.bindArgumentsByName(AbstractAspectJAdvice.java:438)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.calculateArgumentBindings(AbstractAspectJAdvice.java:389)
	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvice(ReflectiveAspectJAdvisorFactory.java:306)
	at org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl.instantiateAdvice(InstantiationModelAwarePointcutAdvisorImpl.java:152)
	at org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl.<init>(InstantiationModelAwarePointcutAdvisorImpl.java:116)
	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisor(ReflectiveAspectJAdvisorFactory.java:216)
	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisors(ReflectiveAspectJAdvisorFactory.java:146)
	at org.springframework.aop.aspectj.annotation.BeanFactoryAspectJAdvisorsBuilder.buildAspectJAdvisors(BeanFactoryAspectJAdvisorsBuilder.java:110)
	at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:95)
	at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:101)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:281)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1130)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1105)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:511)
	... 14 common frames omitted
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 12, 2024
@jhoeller
Copy link
Contributor

jhoeller commented Jul 12, 2024

There have been several follow-up fixes in this area. Could you try this against the just-released 6.1.11 please?

The regular interception might still not work for coroutines, but at least the AdviceMode.ASPECTJ problem should go away.

@jhoeller jhoeller added status: waiting-for-feedback We need additional information before we can continue in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support labels Jul 12, 2024
@malaquf
Copy link
Author

malaquf commented Jul 12, 2024

Hi @jhoeller, thanks for the fast response. I've just tried it with 6.1.11. Unfortunately, the behavior is still the same.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 12, 2024
@simonbasle simonbasle self-assigned this Jul 15, 2024
@simonbasle simonbasle added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Jul 15, 2024
@simonbasle simonbasle added this to the 6.1.12 milestone Jul 15, 2024
@simonbasle simonbasle changed the title CacheInterceptor doesn't handle kotlin coroutines properly Spring coroutines AOP is not compatible with @Cacheable Jul 15, 2024
@malaquf
Copy link
Author

malaquf commented Jul 15, 2024

Thanks for the ultra-blast fast fix!

@simonbasle
Copy link
Contributor

@malaquf no problem, thanks for reporting (and too bad I didn't catch it when fixing the similar issue with @Transactional)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants