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
HandlerDefinitions and HandlerEnhancerDefinitions are shared between multiple Spring Application Contexts #2590
Comments
Thanks once more for filing an issue with us, @nils-christian! First and foremost, did this predicament start occurring with Axon Framework 4.7.1?
I fully agree that the This approach is followed for numerous infrastructure components within the Framework. Granted, the setup causes issues in your environment, I assume? |
Hi @smcvb, The issue is not exclusive to the 4.7.0 release but exists in 4.6.3 as well. I would like to explain our issue with the shared definitions. As you might know, we use multiple instances of Axon in the same application using Spring's hierarchical context. Furthermore, we start some contexts in parallel, which leads to a ConcurrentModificationException in the PayloadAssociationResolver. This is how we detected the issue. I know that this particular issue has been adresses in #2591, but I wonder if there could be any other issues regarding the shared definitions. Could something unexpected break or should the definitions be otherwise threadsafe and everything? Unfortunately, making the bean conditional is not really sufficient. Replacing the static code in all involved classes is rather cumbersome, to be honest. |
Good to know. I assumed as much, but wanted to make sure.
I similarly assume this also occurred in 4.6.3 and before?
A valid concern, @nils-christian, and one I was jumping on right after reading your reply. However, that's not something that's changed recently. At all. Long story short, I'm running some internal errands on the subject right now.
Would you mind specifying what you think should be replaced for your scenario? |
We have seen it after a (seemingly) simple refactoring of a test case on 4.7.X, but the same test case crashes with 4.6.3. So it is not a regression in Axon.
Good to know, thank you.
Agreed. See above. I don't think of this as regression, but rather an already existing behaviour that now concern us.
We tried to replace it and ended up with the following (not yet working) modifications:
Doing that we still get some missing handler (enhancer) definitions, I think. So we might have overlooked something. That said: We are currently only encountering the ConcurrentModificationException in our specific test. So if it is "just" a concurrency issue during startup, I think we can also wait for a version of Axon containing #2591. Also, I just executed our test case in question against 4.7.2-SNAPSHOT of Axon. I can confirm that the original ConcurrentModificationException no longer occurs. However, it seems that the event handler registration does not work reliably when executed in parallel. Interestingly enough, this is the same error I get after rewriting the definitions as described above. I will investigate this further and check if this is an issue on our side or in Axon. |
We double checked and there was indeed another minor issue in our code. It works with 4.7.2-SNAPSHOT. So from our side, #2591 reduces the severity of the issue with the shared definitions. |
Thanks so much for all the feedback here, @nils-christian. Both are acted on during the application's start-up to build the message-handling components Axon Framework can deal with. However, it's such an easy addition to keeping in mind when, for example, you're constructing a
That's a bit too much, indeed. However, I feel this predicament stems from using a hierarchical Spring context, correct? |
Well, yes, but even when using Spring's hierarchical contexts, one wouldn't normally start them in parallel. So I have to admit that our scenario is pretty unique in this regard.
I agree. As mentioned earlier, the bugfix in the upcoming version solves the issue for us. |
Hi,
We noticed that the HandlerDefinitions and HandlerEnhancerDefinitions are shared between otherwise separated Spring Application Contexts. The reason for this is that the HandlerDefinitionFactoryBean uses ClasspathHandlerDefinition and ClasspathHandlerEnhancerDefinition to load some definitions. Those classes use static fields to store the loaded definitions. This breaks with the concept of Spring beans.
Basic information
Steps to reproduce
Please take a look at the provided example project. Please note that we do not use the auto configuration of Axon. Instead we use a hierarchical Spring Context with a configuration class which basically contains Axon's auto configuration. The example application retrieves the HandlerEnhancerDefinitions from both child contexts and calculates the intersection of them.
Expected behaviour
The intersection should be empty.
Actual behaviour
The intersection contains various definitions.
Workaround
Build a custom HandlerDefinitionFactoryBean which doesn't store the objects in a static map. This is difficult though, because the HandlerDefinitionFactoryBean is not marked with ConditionalOnMissingBean.
The text was updated successfully, but these errors were encountered: