firebase-android-sdk: Firebase Auth crashes with OutOfMemoryError in Android 12
[REQUIRED] Step 2: Describe your environment
- Android Studio version: Bumblebee 2021.1.1 Patch 2
- Firebase Component: auth
- Component version: firebase-auth:21.0.3
- Device: Android 12 - Samsung S10
[REQUIRED] Step 3: Describe the problem
Firebase Auth crashes with OutOfMemoryError in Android 12
Steps to reproduce:
This is the console output for one of our Android 12 users getting the crash.
java.lang.OutOfMemoryError: Failed to allocate a 150994952 byte allocation with 25165824 free bytes and 104MB until OOM, target footprint 452092968, growth limit 536870912 at java.util.Arrays.copyOf(Arrays.java:3257) at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124) at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:649) at java.lang.StringBuilder.append(StringBuilder.java:203) at org.json.JSONStringer.string(JSONStringer.java:327) at org.json.JSONStringer.value(JSONStringer.java:261) at org.json.JSONArray.writeTo(JSONArray.java:616) at org.json.JSONStringer.value(JSONStringer.java:242) at org.json.JSONObject.writeTo(JSONObject.java:740) at org.json.JSONObject.toString(JSONObject.java:708) at com.google.firebase.auth.internal.zzbg.zzd(com.google.firebase:firebase-auth@@21.0.3:27) at com.google.firebase.auth.FirebaseAuth.zzH(com.google.firebase:firebase-auth@@21.0.3:13) at com.google.firebase.auth.zzo.zza(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzrv.zzb(com.google.firebase:firebase-auth@@21.0.3:3) at com.google.android.gms.internal.firebase-auth-api.zzuh.zzj(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzue.zzn(com.google.firebase:firebase-auth@@21.0.3:2) at com.google.android.gms.internal.firebase-auth-api.zztg.zzn(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzqe.zzb(com.google.firebase:firebase-auth@@21.0.3:2) at com.google.android.gms.internal.firebase-auth-api.zzup.zza(com.google.firebase:firebase-auth@@21.0.3:24) at com.google.android.gms.internal.firebase-auth-api.zztv.zzf(com.google.firebase:firebase-auth@@21.0.3:4) at com.google.android.gms.internal.firebase-auth-api.zzrl.zzp(com.google.firebase:firebase-auth@@21.0.3:4) at com.google.android.gms.internal.firebase-auth-api.zzth.zzj(com.google.firebase:firebase-auth@@21.0.3:5) at com.google.android.gms.internal.firebase-auth-api.zzrv.zzc(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzui.run(com.google.firebase:firebase-auth@@21.0.3:1) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:920)
Relevant Code:
It calls this code when resuming the app and crashes.
fun checkSignedIn(isPhoneAuth: Boolean) {
if (!isPhoneAuth) {
val fireBaseUser = FirebaseAuth.getInstance().currentUser
fireBaseUser?.let { user ->
user.getIdToken(true)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
task.result?.token?.let { token ->
if (loggingIn) {
login(token, LoginMethod.FACEBOOK)
} else {
signup(token, LoginMethod.FACEBOOK)
}
} ?: kotlin.run {
resetLogin()
}
} else {
resetLogin()
val exception = task.exception
val errorMessage = exception?.message ?: ""
onError(errorMessage)
}
}
} ?: kotlin.run {
if (!isLoading) {
showLogin()
}
}
} else {
val fireBaseUser = FirebaseAuth.getInstance().currentUser
fireBaseUser?.let { user ->
user.getIdToken(true)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
task.result?.token?.let { token ->
saveAccessToken(token)
phoneAuthAccessToken = token
if (loggingIn) {
login(phoneAuthAccessToken, LoginMethod.PHONE)
} else {
signup(phoneAuthAccessToken, LoginMethod.PHONE)
}
} ?: kotlin.run {
resetLogin()
}
} else {
resetLogin()
val exception = task.exception
val errorMessage = exception?.message ?: ""
onError(errorMessage)
}
}
} ?: kotlin.run {
//resetLogin()
if (!isLoading) {
showLogin()
}
}
}
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 27
- Comments: 43 (7 by maintainers)
Hi @Cellaryllis – a fix for both the NPE and OOM will be going out in the next release. However, this issue has proven extremely hard to reproduce, so we’ve been unable to fully verify if the OOM is resolved, unfortunately.
I’ll update this thread again once the new version is released.
Hi folks, thanks for reporting this issue! As an update, we’re currently working on verifying a fix for this issue.
Hello, thanks for verifying the fix! Is there any ETA on when we can expect the update/fix to go live? Our impacted users would love to be able to use the app again.
@rosalyntan Any release soon?
Same for me, not only on Android 12 But it occur a lot since I updated to BOM 29.3.0 Can’t find a way to replicate
There is also a null pointer on firebase auth
Fatal Exception: java.lang.NullPointerException: Attempt to get length of null array at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:248) at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:241) at java.util.ArrayList.add(ArrayList.java:467) at com.google.firebase.auth.internal.zzx.zzc(com.google.firebase:firebase-auth@@21.0.3:8) at com.google.firebase.auth.FirebaseAuth.zzH(com.google.firebase:firebase-auth@@21.0.3:8) at com.google.firebase.auth.zzo.zza(zzo.java:1) at com.google.firebase.auth.zzt.zza$bridge(com.google.firebase:firebase-auth@@21.0.3:5) at com.google.android.gms.internal.firebase-auth-api.zzrv.zzb(com.google.firebase:firebase-auth@@21.0.3:3) at com.google.android.gms.internal.firebase-auth-api.zzuh.zzj(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzue.zzn(com.google.firebase:firebase-auth@@21.0.3:2) at com.google.android.gms.internal.firebase-auth-api.zztg.zzn(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzqe.zzb(com.google.firebase:firebase-auth@@21.0.3:2) at com.google.android.gms.internal.firebase-auth-api.zzup.zza(com.google.firebase:firebase-auth@@21.0.3:24) at com.google.android.gms.internal.firebase-auth-api.zztv.zzf(com.google.firebase:firebase-auth@@21.0.3:4) at com.google.android.gms.internal.firebase-auth-api.zzrl.zzp(com.google.firebase:firebase-auth@@21.0.3:4) at com.google.android.gms.internal.firebase-auth-api.zzth.zzj(com.google.firebase:firebase-auth@@21.0.3:5) at com.google.android.gms.internal.firebase-auth-api.zzrv.zzc(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzui.run(com.google.firebase:firebase-auth@@21.0.3:1) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)
Only solution for now is to downgrade to previous BOM version -_-
I have tested with a few versions and I can confirm that at least the related issue https://github.com/firebase/firebase-android-sdk/issues/3626 is not only happening on Android 12.
And it seems that I need to revert to BoM 29.1.0 , to get rid of this issue. So this issue was most likely introduced, when fixing the memory leak #2387 Released with: https://firebase.google.com/support/release-notes/android#auth_v21-0-2
Working with latest flutter libraries and still getting the crash
firebase_core: ^1.19.2 firebase_auth: ^3.4.2
Am I doing something wrong?
Oh yes! I pointed this out to the FlutterFire crew and behold - a merged PR already! https://github.com/firebase/flutterfire/pull/8967 Please understand that fixes the ConcurrentModificationException which is (was!) a real FlutterFire issue but is distinct from the issue logged here. Hope this helps
Thanks a lot @mikehardy ! I will follow you suggestion and propose the PR if it helps.
@efstathiosntonas yeah saw this in the release notes as I was reading them just now - for react-native-firebase you may adopt this immediately by overriding the BoM to be 30.2.0 like so https://rnfirebase.io/#android and we’ll have a release “real soon now” that just incorporates it by default. I want to add Android 13 notification permissions first though as that will be a huge deal for people
@mikehardy just fyi 🥰
Is this fixed in BoM 30.0.0?
Same here.
[...] Failed to allocate a 25459360 byte allocation with 2097152 free bytes and 23MB until OOM
For us it’s only 1 user crashing over 2000 times. It happens every 1-5min.
On Applications create we’re attaching an
AuthStateListener
, waiting for it to complete and fetching the current user fromFirebaseAuth
in order to do some verification.Versions: bom:29.3.0 / Authentication version 21.0.3
Device Brand:LENOVO Model:P70 Orientation: Portrait RAM free: 694.25 MB Disk free: 2.59 GB Operating System Version:Android 5.1
I am also going to revert to the previous BoM, before releasing our apps to the public.