mixpanel / mixpanel-android

Official Android Tracking Library for Mixpanel Analytics
http://mixpanel.com/
Apache License 2.0
1.02k stars 364 forks source link

ANR due to Mixpanel#getInstance #831

Open arunsudharsan opened 4 months ago

arunsudharsan commented 4 months ago
at jdk.internal.misc.Unsafe.park (Native method)
  at java.util.concurrent.locks.LockSupport.park (LockSupport.java:194)
  at java.util.concurrent.FutureTask.awaitDone (FutureTask.java:447)
  at java.util.concurrent.FutureTask.get (FutureTask.java:190)
  at com.mixpanel.android.mpmetrics.PersistentIdentity.getTimeEvents (PersistentIdentity.java:292)
  at com.mixpanel.android.mpmetrics.MixpanelAPI.<init> (MixpanelAPI.java:158)
  at com.mixpanel.android.mpmetrics.MixpanelAPI.<init> (MixpanelAPI.java:123)
  at com.mixpanel.android.mpmetrics.MixpanelAPI.getInstance (MixpanelAPI.java:505)
  at com.mixpanel.android.mpmetrics.MixpanelAPI.getInstance (MixpanelAPI.java:278)
  at com.meesho.supply.di.modules.AnalyticsModule.provideSupplierMixpanelApi (AnalyticsModule.java:38)
  at com.meesho.supply.di.modules.AnalyticsModule_ProvideSupplierMixpanelApiFactory.provideSupplierMixpanelApi (AnalyticsModule_ProvideSupplierMixpanelApiFactory.java:45)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl.supplierMixpanelMixpanelAPI (DaggerSupplyApplication_HiltComponents_SingletonC.java:8358)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get0 (DaggerSupplyApplication_HiltComponents_SingletonC.java:9240)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get (DaggerSupplyApplication_HiltComponents_SingletonC.java:10187)
  at dagger.internal.DoubleCheck.get (DoubleCheck.java:47)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl.provideSupplierMixpanelDispatcher (DaggerSupplyApplication_HiltComponents_SingletonC.java:8362)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl.mapOfByteAndDispatcher (DaggerSupplyApplication_HiltComponents_SingletonC.java:8402)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get0 (DaggerSupplyApplication_HiltComponents_SingletonC.java:9225)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get (DaggerSupplyApplication_HiltComponents_SingletonC.java:10187)
  at dagger.internal.SingleCheck.get (SingleCheck.java:49)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl.injectSupplyApplication2 (DaggerSupplyApplication_HiltComponents_SingletonC.java:9181)
  at com.meesho.supply.main.DaggerSupplyApplication_HiltComponents_SingletonC$SingletonCImpl.injectSupplyApplication (DaggerSupplyApplication_HiltComponents_SingletonC.java:9104)
  at com.meesho.supply.main.Hilt_SupplyApplication.hiltInternalInject (Hilt_SupplyApplication.java:52)
  at com.meesho.supply.main.Hilt_SupplyApplication.onCreate (Hilt_SupplyApplication.java:43)
  at com.meesho.supply.main.SupplyApplication.onCreate (SupplyApplication.kt:92)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1261)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:7311)

We are also facing this issue during the init.

Upon debugging found that the method PersistentIdentity.getTimeEvents() is utilized for retrieving a map containing event names mapped to their respective start times, represented in milliseconds since epoch. This map is subsequently stored within the variable mEventTimings.

Mixpanel#getInstance is suggested to be called from the main thread as per the doc : "The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application)." But this blocking IO call is happening on the main thread.

Screenshot 2024-03-15 at 2 26 19 PM
RngNoah commented 3 months ago

I also encountered this problem, the version I am using is 7.3.1. Is anyone dealing with this issue?