facebook / facebook-android-sdk

Used to integrate Android apps with Facebook Platform.
https://developers.facebook.com/docs/android
Other
6.13k stars 3.65k forks source link

Fatal Exception: java.util.ConcurrentModificationException: #1260

Open JhinSir opened 2 weeks ago

JhinSir commented 2 weeks ago

Checklist before submitting a bug report

Java version

JDK11

Android version

Android13,14,12,10,11

Android SDK version

16.2.0

Installation platform & version

Gradle

Package

Core & AppEvents

Goals

The program is normal

Expected results

No crash

Actual results

Program startup crashes Fatal Exception: java.util.ConcurrentModificationException: at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:760) at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:782) at com.facebook.internal.FetchedAppGateKeepersManager.getGateKeepersForApplication(FetchedAppGateKeepersManager.kt:165) at com.facebook.internal.FetchedAppGateKeepersManager.getGateKeeperForKey(FetchedAppGateKeepersManager.kt:177) at com.facebook.internal.FeatureManager.getGKStatus(FeatureManager.kt:107) at com.facebook.internal.FeatureManager.isEnabled(FeatureManager.kt:54) at com.facebook.internal.FeatureManager.isEnabled(FeatureManager.kt:54) at com.facebook.internal.Utility.setAppEventAttributionParameters(Utility.kt:578) at com.facebook.applinks.AppLinkData.fetchDeferredAppLinkFromServer(AppLinkData.java:143) at com.facebook.applinks.AppLinkData.access$000(AppLinkData.java:36) at com.facebook.applinks.AppLinkData$1.run(AppLinkData.java:131) 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)

Steps to reproduce

Unable to reproduce

Code samples & details

After integrating the SDK, calling the AppLinkData.fetchDeferredAppLinkData method in the Application's oncreate method, 5K+ crashes were observed on firbase. However, the crash cannot be reproduced locally.
The following is my debugging process:
1. Because I called AppLinkData.fetchDeferredAppLinkData in the Kotlin coroutine, I am not sure whether there is an asynchronous concurrency problem in a multi-threaded environment
2. The FetchedAppGateKeepersManager class in the source code, the following code:
      val output: MutableMap<String, Boolean> = HashMap()
      val jsonObject: JSONObject = fetchedAppGateKeepers[applicationId] ?: JSONObject()
      val jsonIterator = jsonObject.keys()
      while (jsonIterator.hasNext()) {
        val key = jsonIterator.next()
        output[key] = jsonObject.optBoolean(key)
      }
Printing the log, I found that even when multiple threads accessed and modified at the same time, it did not affect the iteration here. So I am wondering what other possible points may cause this error?
3.Is it possible that cacheList is empty under certain circumstances? Is it possible that the SDK initialization and the AppLinkData.fetchDeferredAppLinkData method are executed simultaneously under certain extreme conditions when the App is started?
JhinSir commented 2 weeks ago

Can you explain to me what conditions may trigger this error when the getGateKeepersForApplication method is running? From my current debugging log observation, there is no problem even when accessing and modifying the fetchedAppGateKeepers variable in a multi-threaded environment