-
Notifications
You must be signed in to change notification settings - Fork 369
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
Fix: Add synchronized blocks to prevent ConcurrentModificationException #1876
Fix: Add synchronized blocks to prevent ConcurrentModificationException #1876
Conversation
Thank you for digging into this issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets try using the @synchronized class/function annotations to make this read more cleanly.
|
ensure additional thread safety in SingletonModelStore
Prevent a null id
@brismithers some additions here based on your analysis in Asana, if you wouldn't mind taking a quick look to ensure I got it all! |
I believe the |
nit: this doesn't need to by synchronized since it is only used by this method as a local variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @brismithers, @emawby, @jkasten2, @nan-li, and @shepherd-l)
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/Model.kt
line 125 at r2 (raw file):
Previously, brismithers (Brian Smith) wrote…
I believe the
data.clear()
is needed, if the incoming model doesn't have a particular property set the current model will not have that property removed. I wonder if it might be safer to build up a localMutableMap
then at the end replacedata
with the new instance?
Done.
…xception Fix: Add synchronized blocks to prevent ConcurrentModificationException
…xception Fix: Add synchronized blocks to prevent ConcurrentModificationException
…xception Fix: Add synchronized blocks to prevent ConcurrentModificationException
Description
One Line Summary
Add synchronized blocks to prevent ConcurrentModificationException
Details
Motivation
Reports of ConcurrentModificationException occurring in various areas of the SDK:
ModelStore.kt
Model.kt
EventProducer.kt
EventProducer.fire - #1858
Scope
The methods reported in the various stack traces were wrapped in synchronized blocks to make them thread-safe.
Additional blocks may need to be added to other areas of the SDK if additional crashes are reported in the future.
Testing
Manual testing
The exact conditions needed to trigger these exceptions are unclear--the only way I was able to reproduce a similar crash was from some custom code. Adding synchronized blocks to this code prevented the crash from occurring on Pixel 7 emulator running Android 33. If reproduction steps can be verified, eventual unit tests may be added in the future to help check for these exceptions.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is