optimizely/android-sdk

ConcurrentModificationException in Optimizely.filterAttributes()

fingertricks opened this issue · 3 comments

We are seeing a low-frequency crash originating within the Optimizely Android SDK (v2.1.0). This is observed when calling OptimizelyClient.isFeatureEnabled():

Caused by java.util.ConcurrentModificationException
       at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:411)
       at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:430)
       at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:430)
       at com.optimizely.ab.Optimizely.filterAttributes(Optimizely.java:776)
       at com.optimizely.ab.Optimizely.isFeatureEnabled(Optimizely.java:362)
       at com.optimizely.ab.android.sdk.OptimizelyClient.isFeatureEnabled(OptimizelyClient.java:360)
...

As a temporary workaround we have added a try...catch around calls to isFeatureEnabled().

We've seen around 20 crashes in the last couple of weeks since we integrated the Optimizely SDK.

After further investigation, we've found the cause of this was that we were passing a mutable attributes map to Optimizely, and in rare cases that map could be modified on a background thread. We've resolved this by passing an immutable map of attributes into activate(), isFeatureEnabled() or track().

Leaving this open in case the SDK team want to consider copying the attributes passed in, or making the documentation clearer.

@fingertricks just wanted to let you know we have merged a PR to make a copy of the original attributes list so that we don't have this problem in the future. Thanks for the feedback!

In 3.0.0-RC we are copying the attribute map to make sure there is no immutability issues. So, I'm going to close this (we are releasing 3.0.0 soon).