Hi all, getting this crash (`ConcurrentModificatio...
# support
c
Hi all, getting this crash (
ConcurrentModificationException
) in our production build for Android SDK. Does anyone have any idea about this issue? Thanks in advance.
k
Hi @cold-army-34907 , Can you please share the version of Android SDK, you are using ?
โœ… 1
c
We are using
com.rudderstack.android.sdk:core:1.7+
. Is there any specific version we are supposed to use?
k
It's always suggested to use the latest version, but can you please share the exact version you are using in your app ?
c
1.7.1
k
We have made some changes around how we use GSON in our recent releases, please try upgrading to the latest version and let us know how it goes
c
Noted, thanks for the quick update. ๐Ÿ™Œ
@kind-carpenter-27609 We're using Moshi in Retrofit as our parser, now after updating Ruddertack to latest version. Our app level Retrofit is crashing with:
Unable to create @Body converter
k
Can you please share the complete logs you are seeing ?
Any stacktrace ? May I know how did we arrive at the conclusion that this crash was due to Rudder Android SDK ?
c
Hi @kind-carpenter-27609. This is the stacktrace with latest version of Rudderstack SDK:
1.21.1
. Also, We're using Moshi as our main retrofit parser. Initially, It was creating problems because of different versions being used in our app and in Rudderstack SDK. So we excluded moshi dependency from Rudderstack SDK, using
exclude(group = "com.squareup.moshi")
. But still, we're getting the same crash. Do you have any idea regarding this?
๐Ÿ‘€ 1
k
CC <!subteam^S04QT1G74Q3|@sdk-team>
n
@cold-army-34907 Itโ€™s perfectly fine to exclude Moshi. But for the error, can you please let us know if you are using the reset api?
c
Hi @narrow-wolf-10290 No, We're not using reset API from the SDK
n
Thanks @cold-army-34907. I am just trying to get a peek into your instrumentation to get a better understanding. Is there a possibility for identify to be called multiple times concurrently across threads?
c
Yes. @narrow-wolf-10290. We're using
RudderClient.getInstance()?.identify(it)
at multiple places, which is our use-case as of now. Also, we're using the same for other libraries like Amplitude and Clevertap, but there's no such crash there. Also, we've encountered multiple crashes in SDK, some of them related to SQLLite. PFA: Screenshot for the crashes
n
Thanks @cold-army-34907 we are trying to reproduce the same. Is it possible for you to explain your instrumentation by providing snippets of alias and identify calls. Also are you using โ€œgetTraits()โ€ method?
c
No, we're not calling getTraits(). Although, we're using this method.
Copy code
public RudderTraits() {
        Application application = RudderClient.getApplication();
        if (application != null) {
            this.anonymousId = RudderContext.getAnonymousId();
        }
    }
Below is our use-case:
Copy code
RudderTraits().also { rudderTraits ->
                        profile.entries.forEach { entries ->
                            entries.value?.let {
                                rudderTraits.put(entries.key, it)
                            }
                        }
                    }.also {
                        RudderClient.getInstance()?.identify(it)
                    }
๐Ÿ‘€ 1
Can we connect sometime tomorrow if possible. It'll be easy to debug and better understand the use-case for both of us? @narrow-wolf-10290
n
Thanks @cold-army-34907 let me get back to you, while we try to debug more.
@shy-kite-21035 can you help us schedule a call on this issue?
s
@narrow-wolf-10290 sure will help setup the call. Who else from our side will join? I ll look for available slots today and tomorrow
n
Thanks. You can just add me.
m
Hi @Prashanth please feel free to setup a call today or tomorrow in calendly I will add Debanjan to the call
c
Hi @shy-kite-21035, I've scheduled a call for tomorrow at 4pm including one of my colleague.
m
I have added Debanjan to the call.
c
Method: logEvent()
Copy code
override fun logEvent(event: String, params: Map<String, Any>?) {
        RudderProperty().also { rp ->
            val paramsCopy = params?.let { it1 -> HashMap(it1) }.orElse { HashMap() }
            paramsCopy["platform"] = "android"
            paramsCopy.entries.forEach {
                it.value?.let { value ->
                    rp.put(it.key, value)
                }
            }
        }.also {
            rudderclient?.track(event, it)
        }

    }
Method: updateUserProfile()
Copy code
fun updateUserProfile(profile: Map<String, Any>, endpoints: List<Int>) {
        endpoints.forEach { ep ->
            when (ep) {
                AnalyticsHelper.FIREBASE -> profile.map {
                    FloBooks.firebaseAnalytics.setUserProperty(
                        it.key,
                        it.value.toString()
                    )
                }

                AnalyticsHelper.CLEVERTAP -> FloBooks.clevertapDefaultInstance?.pushProfile(profile)
                AnalyticsHelper.AMPLITUDE -> {
                    Amplitude.getInstance().setUserProperties(JSONObject(profile))
                    try {
                        RudderTraits().also { rudderTraits ->
                            val profileCopy = ConcurrentHashMap(profile)
                            profileCopy.entries.forEach { entries ->
                                entries.value?.let {
                                    rudderTraits.put(entries.key, it)
                                }
                            }
                        }.also {
                            RudderClient.getInstance()?.identify(it)
                        }
                    }catch (e : Exception){
                        FirebaseCrashlytics.getInstance().recordException(e)
                    }
                }
            }
        }
    }
Method: setIdentity()
Copy code
fun setIdentity(phoneNumber: String = "", name: String = "", email: String = "") {
        val profile = HashMap<String, Any>()
        profile[AttrKeys.NAME] = name
        profile[AttrKeys.IDENTITY] = phoneNumber
        profile[AttrKeys.EMAIL] = email

        val phone = if (phoneNumber.isEmpty())
            Prefs.getString(PrefKeys.PHONE_NUMBER)
        else {
            Prefs.putString(PrefKeys.PHONE_NUMBER, phoneNumber)
            phoneNumber
        }

        phone?.let {
            profile[AttrKeys.PHONE] = it

            try {
                if (it.isNotEmpty())
                    RudderClient.getInstance()?.identify(it)
            }catch (e : Exception){
                FirebaseCrashlytics.getInstance().recordException(e)
            }

            Amplitude.getInstance().userId = it
            FloBooks.firebaseAnalytics.setUserId(it)
            FloBooks.firebaseCrashlytics.setUserId(it)
            updateUserProfile(profile, listOf(AnalyticsHelper.CLEVERTAP, AnalyticsHelper.AMPLITUDE))
            Singular.setCustomUserId(it)
        }
    }
Method to reproduce:
Copy code
fun main() {
    val profile =HashMap<String, Any>()
    profile["initialKey"] = "initialValue"
    // Thread to modify the profile map
    thread {
        repeat(100) {
            Thread.sleep(10) // Sleep to give a chance for the other thread to start iterating
            profile["key$it"] = "value$it"
        }
    }
    // Your function (slightly modified for direct execution)
    thread {
        repeat(100) {
            RudderTraits().also { rudderTraits ->
                val profileCopy = HashMap(profile)
                profileCopy.entries.forEach {
                    rudderTraits.put(it.key, it.value)
                }
            }.also {
                RudderClient.getInstance()?.identify(it)
            }
            Thread.sleep(10) // Sleep to allow concurrent modification
        }
    }.join()
}
๐Ÿ™Œ 1
n
Thanks @cold-army-34907 I will look into it.
๐Ÿ™Œ 1
Hey @cold-army-34907 we have released 1.21.2 with the fix for the issue. Can you please check and let us know if it works.
โœ… 1
c
Thanks for the update. We'll update the SDK to this version.
c
Hey @cold-army-34907, Can you please let us know if the issue is solved for you or not?
c
Hey Abhishek. We are sending a release today itself, will let you know after that if this is fixed or not.
๐Ÿ‘ 1