Project: mule
Issue MULE-6889: Concurrent Modification Exception when using the Async Message Proccessor inside a foreach
It's getting more usual in iApps that we get a collection of elements, and we want to process each element asynchronously. For that reason, we are using the "for-each" message processor, and inside it, we throw an "Async" with a "Flow-Ref" to the flow that process each element. The problem is that it's seems to be a bug that randomly (let's say 4 our of 10) throws a java.util.ConcurrentModificationException. As you can see in the log output, this exception is thrown while the Async is copying the event to create a new one to fire a new thread. The exact error is located at DefaultMuleEvent.java:938, where it says: message.getInvocationPropertyNames(). So, what i guess it's happening here is that when creating a new event, the copy is saving some kind of reference to the same maps instead of creating a new ones. Then, if some new flow var is created in the process item flow, while the async is still firing new thread (that means, copy new events), they are getting mixed up and crash. I'm attached a simple Studio 3.4 GA based project where you can reproduce the bug. Just run the app, and you will see the exception in the console. If you see the following log: "Tenant ID: merlo - RUNNING - Waiting for: 1" and you don't see any exception, please turn down and run the app again. As i said, it doesn't happen 100% of times.
Story points: 2