Skip to content

Fix ConcurrentModificationException when serializing StepDataAction#243

Merged
drodriguezhdez merged 4 commits into
masterfrom
drodriguezhdez/fix_concurrent_modif_exception
Sep 2, 2021
Merged

Fix ConcurrentModificationException when serializing StepDataAction#243
drodriguezhdez merged 4 commits into
masterfrom
drodriguezhdez/fix_concurrent_modif_exception

Conversation

@drodriguezhdez

Copy link
Copy Markdown
Collaborator

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

What does this PR do?

This PR adds a synchronize on the run instance on modification of the StepDataAction internal map.

This fixes the race condition detected in a scenario of parallel pipelines, where the WorkflowRun.save() method raises a ConcurrentModificationException because the map is modified by other Thread.

AIUI run here should always be an instance of WorkflowRun, which synchronizes on itself before saving, which should prevent the ConcurrentModificationException.

02:10:38  java.util.ConcurrentModificationException
02:10:38    at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1493)
02:10:38    at java.base/java.util.HashMap$EntryIterator.next(HashMap.java:1526)
02:10:38    at java.base/java.util.HashMap$EntryIterator.next(HashMap.java:1524)
02:10:38    at com.thoughtworks.xstream.converters.collections.MapConverter.marshal(MapConverter.java:75)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
02:10:38    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:275)
02:10:38    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:262)
02:10:38  Caused: java.lang.RuntimeException: Failed to serialize org.datadog.jenkins.plugins.datadog.traces.StepDataAction#stepDataByDescriptor for class org.datadog.jenkins.plugins.datadog.traces.StepDataAction
02:10:38    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:266)
02:10:38    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:233)
02:10:38    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:150)
02:10:38    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:219)
02:10:38    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:158)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
02:10:38    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeBareItem(AbstractCollectionConverter.java:94)
02:10:38    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:66)
02:10:38    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeCompleteItem(AbstractCollectionConverter.java:81)
02:10:38    at com.thoughtworks.xstream.converters.collections.CollectionConverter.marshal(CollectionConverter.java:74)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
02:10:38    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:275)
02:10:38    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:262)
02:10:38  Caused: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
02:10:38    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:266)
02:10:38    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:233)
02:10:38    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:150)
02:10:38    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:219)
02:10:38    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:158)
02:10:38    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
02:10:38    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
02:10:38    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
02:10:38    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1278)
02:10:38    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1267)
02:10:38    at com.thoughtworks.xstream.XStream.toXML(XStream.java:1240)
02:10:38    at hudson.util.XStream2.toXMLUTF8(XStream2.java:312)
02:10:38    at org.jenkinsci.plugins.workflow.support.PipelineIOUtils.writeByXStream(PipelineIOUtils.java:34)
02:10:38    at org.jenkinsci.plugins.workflow.job.WorkflowRun.save(WorkflowRun.java:1210)
02:10:38    at hudson.tasks.junit.JUnitResultArchiver.parseAndSummarize(JUnitResultArchiver.java:289)
02:10:38    at hudson.tasks.junit.pipeline.JUnitResultsStepExecution.run(JUnitResultsStepExecution.java:63)
02:10:38    at hudson.tasks.junit.pipeline.JUnitResultsStepExecution.run(JUnitResultsStepExecution.java:29)
02:10:38    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
02:10:38    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
02:10:38    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
02:10:38    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
02:10:38    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
02:10:38    at java.base/java.lang.Thread.run(Thread.java:834)

Description of the Change

Alternate Designs

Possible Drawbacks

Verification Process

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@drodriguezhdez drodriguezhdez added the changelog/Fixed Fixed features results into a bug fix version bump label Sep 2, 2021
public StepData get(final FlowNode flowNode) {
return stepDataByDescriptor.get(flowNode.getId());
public StepData synchronizedGet(final Run<?,?> run, final FlowNode flowNode) {
synchronized (run){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you sych'ing over run and not over the hashmap of the data action?

@drodriguezhdez drodriguezhdez Sep 2, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the lock object is the run instance in the WorkflowRun.save() method.
If we synchronize on the hashmap directly will not resolve the issue, because that is not the lock object used when the action is saved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Fixed Fixed features results into a bug fix version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants