Skip to content

Conversation

@marchof
Copy link
Member

@marchof marchof commented Dec 4, 2015

Hi guys,

I'm having a problem with RuntimeData and specifically with ExecutionDataStore. The data store has a map: Map<Long, ExecutionData> entries which causes a concurrent access a problem with the following exception:

java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
    at java.util.HashMap$ValueIterator.next(HashMap.java:1458)
    at org.jacoco.agent.rt.internal_c57fe0e.core.data.ExecutionDataStore.accept(ExecutionDataStore.java:167)
    at org.jacoco.agent.rt.internal_c57fe0e.core.runtime.RuntimeData.collect(RuntimeData.java:87)
    at org.jacoco.agent.rt.internal_c57fe0e.output.MongoDbOutput.writeExecutionData(MongoDbOutput.java:54)
    at org.jacoco.agent.rt.internal_c57fe0e.Agent.shutdown(Agent.java:132)
    at org.jacoco.agent.rt.internal_c57fe0e.Agent$1.run(Agent.java:49)

Note: MongoDbOutput is a custom created MongoDB sink

The RuntimeData has a comment saying that is thread safe. That's not the case anymore since ExecutionDataStore is not thread safe

@bjkail
Copy link
Contributor

bjkail commented Dec 4, 2015

RuntimeData looks thread-safe to me. ConcurrentModificationException can also occur if the HashMap is changed while being iterated. Does MongoDbOutput call other RuntimeData methods from the IExecutionDataVisitor/ISessionInfoVisitor that it passes to collect?

@ihr
Copy link
Author

ihr commented Dec 4, 2015

Hi,

For a class to be a thread-safe its fields should also be thread-safe. MongoDbOutput uses only one method: RuntimeData#collect.

@marchof marchof added type: bug 🐛 Something isn't working component: core labels Dec 4, 2015
@marchof marchof self-assigned this Dec 4, 2015
@marchof
Copy link
Member

marchof commented Dec 4, 2015

Good catch! This is actually not a multi-threading-issue but a re-entrance issue. When the provided callbacks itself load new classes the internal ExecutionDataStore can be modified from within the same thread.

@marchof marchof added this to the 0.7.6 milestone Dec 4, 2015
marchof added a commit that referenced this pull request Dec 4, 2015
GitHub #364: Avoid ConcurrentModificationException during shutdown.
@marchof marchof merged commit 8d8f7bf into master Dec 4, 2015
@Godin Godin deleted the issue-364 branch December 4, 2015 21:44
@jacoco jacoco locked and limited conversation to collaborators Jan 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

component: core type: bug 🐛 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants