iteratehq / iterate-android

Iterate Android SDK
MIT License
3 stars 1 forks source link

[Bug] ANR when initialising the Iterate SDK #77

Closed florianPOLARSTEPS closed 5 months ago

florianPOLARSTEPS commented 5 months ago

Description.

When starting up the Iterate SDK we are seeing a large number of ANRs in our crash tracking setup.

java.lang.Thread.sleep (Native method)
java.lang.Thread.sleep (Thread.java:450)
java.lang.Thread.sleep (Thread.java:355)
android.security.KeyStoreSecurityLevel.interruptedPreservingSleep (KeyStoreSecurityLevel.java:206)
android.security.KeyStoreSecurityLevel.createOperation (KeyStoreSecurityLevel.java:115)
android.security.keystore2.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized (AndroidKeyStoreCipherSpiBase.java:334)
android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineInit (AndroidKeyStoreCipherSpiBase.java:171)
javax.crypto.Cipher.tryTransformWithProvider (Cipher.java:2985)
javax.crypto.Cipher.tryCombinations (Cipher.java:2892)
javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider (Cipher.java:2797)
javax.crypto.Cipher.chooseProvider (Cipher.java:774)
javax.crypto.Cipher.init (Cipher.java:1144)
javax.crypto.Cipher.init (Cipher.java:1085)
com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encryptInternal (AndroidKeystoreAesGcm.java:84)
com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt (AndroidKeystoreAesGcm.java:68)
com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead (AndroidKeystoreKmsClient.java:248)
com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.getAead (AndroidKeystoreKmsClient.java:165)
com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey (AndroidKeysetManager.java:267)
com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build (AndroidKeysetManager.java:236)
androidx.security.crypto.EncryptedSharedPreferences.create (EncryptedSharedPreferences.java:155)
androidx.security.crypto.EncryptedSharedPreferences.create (EncryptedSharedPreferences.java:120)
com.iteratehq.iterate.data.local.DefaultIterateSharedPrefs$prefs$2.invoke (IterateSharedPrefs.kt:39)
com.iteratehq.iterate.data.local.DefaultIterateSharedPrefs$prefs$2.invoke (IterateSharedPrefs.kt:34)
kotlin.SynchronizedLazyImpl.getValue (LazyJVM.kt:74)
com.iteratehq.iterate.data.local.DefaultIterateSharedPrefs.getPrefs (IterateSharedPrefs.kt:34)
com.iteratehq.iterate.data.local.DefaultIterateSharedPrefs.getUserAuthToken (IterateSharedPrefs.kt:66)
com.iteratehq.iterate.data.DefaultIterateRepository.getUserAuthToken (DefaultIterateRepository.java:92)
com.iteratehq.iterate.Iterate.initAuthToken (Iterate.kt:261)
com.iteratehq.iterate.Iterate.init (Iterate.kt:71)
com.iteratehq.iterate.Iterate.init$default (Iterate.kt:54)

Question

Is it safe to offload the initialization to another thread?

Improvement

As a developer I would expect threading logic to be handled inside the library. Or at least the documentation should point out that Iterate.init() should be called off the main thread unlike it is currently described in the Application.onCreate() directly.

msingleton commented 5 months ago

Thanks @florianPOLARSTEPS, we're fixing this and making init main-safe, i'll ping you once we release the version with it

msingleton commented 5 months ago

@florianPOLARSTEPS this and the other issue are fixed and released in the 1.2.0 version if you want to pick that up, thanks for the issues!

florianPOLARSTEPS commented 5 months ago

@msingleton Thanks for taking a look. We will upgrade in one of the upcoming releases and let you know if there are any more issues. 👍