Skip to content
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

RUM-4329: Fix ConcurrentModificationException during features iteration #2012

Conversation

0xnm
Copy link
Member

@0xnm 0xnm commented Apr 29, 2024

What does this PR do?

It is possible to have a crash like that:

java.util.ConcurrentModificationException
	at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:760)
	at java.util.LinkedHashMap$LinkedEntryIterator.next(LinkedHashMap.java:792)
	at java.util.LinkedHashMap$LinkedEntryIterator.next(LinkedHashMap.java:790)
	at com.datadog.android.core.DatadogCore.updateFeatureContext(SourceFile:65)
	at com.datadog.android.rum.internal.domain.scope.RumViewScope.<init>(SourceFile:21)
	at com.datadog.android.rum.internal.domain.scope.RumViewScope.<init>(SourceFile:31)
	at com.datadog.android.rum.internal.domain.scope.RumViewManagerScope.handleEvent(SourceFile:620)
	at com.datadog.android.rum.internal.domain.scope.RumSessionScope.handleEvent(SourceFile:246)
	at com.datadog.android.rum.internal.domain.scope.RumApplicationScope.handleEvent(SourceFile:356)
	at androidx.lifecycle.DispatchQueue$$ExternalSyntheticLambda0.run(SourceFile:278)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
	at java.lang.Thread.run(Thread.java:1012)

The problem is that DatadogCore.features can be accessed from different threads. This PR makes access for the items of this collection thread-safe.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm 0xnm requested review from a team as code owners April 29, 2024 14:37
@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.69%. Comparing base (0c3e683) to head (29df747).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2012      +/-   ##
===========================================
- Coverage    83.76%   83.69%   -0.07%     
===========================================
  Files          488      488              
  Lines        17779    17778       -1     
  Branches      2667     2667              
===========================================
- Hits         14892    14879      -13     
- Misses        2174     2178       +4     
- Partials       713      721       +8     
Files Coverage Δ
...ain/kotlin/com/datadog/android/core/DatadogCore.kt 81.98% <100.00%> (ø)

... and 23 files with indirect coverage changes

Copy link
Member

@xgouchet xgouchet left a comment

Choose a reason for hiding this comment

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

Note

NitPick: it'd be nice to write a test that reproduces this issue, and then ensure the fix fixes it

@0xnm 0xnm force-pushed the nogorodnikov/rum-4329/fix-concurrent-modification-exception-during-features-iteration branch 2 times, most recently from 08e762c to c5d5456 Compare April 30, 2024 08:18
@0xnm
Copy link
Member Author

0xnm commented Apr 30, 2024

@xgouchet fair point, I've updated my PR with test.

@0xnm 0xnm closed this Apr 30, 2024
@0xnm 0xnm reopened this Apr 30, 2024
@0xnm 0xnm requested a review from xgouchet April 30, 2024 08:19
@0xnm 0xnm force-pushed the nogorodnikov/rum-4329/fix-concurrent-modification-exception-during-features-iteration branch from c5d5456 to 29df747 Compare April 30, 2024 08:20
@0xnm 0xnm merged commit 2adb85c into develop Apr 30, 2024
21 checks passed
@0xnm 0xnm deleted the nogorodnikov/rum-4329/fix-concurrent-modification-exception-during-features-iteration branch April 30, 2024 09:49
@xgouchet xgouchet added this to the 2.9.X milestone Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants