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

RuntimeData not thread safe #364

Merged
merged 1 commit into from Dec 4, 2015

Conversation

Projects
None yet
3 participants
@marchof
Member

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

This comment has been minimized.

Show comment
Hide comment
@bjkail

bjkail Dec 4, 2015

Contributor

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?

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

This comment has been minimized.

Show comment
Hide comment
@ihr

ihr 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.

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

This comment has been minimized.

Show comment
Hide comment
@marchof

marchof Dec 4, 2015

Member

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.

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

Merge pull request #364 from jacoco/issue-364
GitHub #364: Avoid ConcurrentModificationException during shutdown.

@marchof marchof merged commit 8d8f7bf into master Dec 4, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@Godin Godin deleted the issue-364 branch Dec 4, 2015

@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.