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

ApplicationListener potentially invoked twice in circular reference with proxy [SPR-15452] #20013

Closed
spring-issuemaster opened this issue Apr 13, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Apr 13, 2017

Ilya Serkov opened SPR-15452 and commented

ApplicationEvent can be received by ApplicationListener two times.

Can be reproduced when these conditions coincide:

  1. Have at least two listener beans
  2. Listeners implement ApplicationListener
  3. One listener has dependency on another listener (@Autowired)
  4. Listeners must have cyclic dependency with another bean
  5. Listener which invoked twice must have at least one @Transactional method

Affects: 4.2.6

Referenced from: commits a2b3561, 9abf249

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2017

Juergen Hoeller commented

Is one of the listener invocations going straight to the target object and one through the transactional proxy? Or are both going to the proxy?

I'm happy to consider more defensive handling there. However, please be aware that we only support cyclic dependencies in a lenient fashion, i.e. with various guarantees not applying. Our general recommendation certainly is to break the cyclic dependency, e.g. by factoring out a common delegate.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2017

Ilya Serkov commented

Is one of the listener invocations going straight to the target object and one through the transactional proxy? Or are both going to the proxy?

First case - "one going straight to the target object and one through the transactional proxy".

In
org.springframework.context.event.AbstractApplicationEventMulticaster.ListenerRetriever#applicationListeners
I can see two subscriptions for one listener - straight & proxy

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 15, 2017

Juergen Hoeller commented

We're explicitly replacing a target ApplicationListener with its singleton proxy, if any: AbstractApplicationEventMulticaster checks this on registration through addApplicationListener now, where an existing listener object is given, whereas this cannot happen for registration by bean name in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.