Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirebaseAuthFallbackService memory leak #2387

Closed
dimiitpk opened this issue Jan 31, 2021 · 75 comments
Closed

FirebaseAuthFallbackService memory leak #2387

dimiitpk opened this issue Jan 31, 2021 · 75 comments
Assignees
Labels

Comments

@dimiitpk
Copy link

dimiitpk commented Jan 31, 2021

[READ] Step 1: Are you in the right place?

yes

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 4.1.2 Stable
  • Firebase Component: Firebase Authentication
  • Component version: 20.0.2

[REQUIRED] Step 3: Describe the problem

LeakCanary is telling me that "FirebaseAuthFallbackService " is leaking.
I just "AuthStateListener" in my ActivityClass which lives through the entire app lifecycle, to check if the user signed out.
And "Firebase.auth" for taking currentUser instance. That's all

Steps to reproduce:

Happening every time I open the app, sometimes when I close the app, sometimes when It goes to the background, LeakCanary starts dumping the heap and throwing this memory leak.

Relevant Code:

┬───
│ GC Root: Global variable in native code
│
├─ com.google.firebase.auth.api.fallback.service.zza instance
│    Leaking: UNKNOWN
│    Retaining 1.7 kB in 10 objects
│    zza instance of com.google.firebase.auth.api.fallback.service.
│    FirebaseAuthFallbackService
│    ↓ zza.zza
│          ~~~
╰→ com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
​  instance
​     Leaking: YES (ObjectWatcher was watching this because com.google.firebase.
​     auth.api.fallback.service.FirebaseAuthFallbackService received
​     Service#onDestroy() callback)
​     Retaining 1.2 kB in 9 objects
​     key = d411935b-9bcd-4a8d-8362-a6c8687aec0e
​     watchDurationMillis = 5285
​     retainedDurationMillis = 281
​     mApplication instance of com.upgrades.venue.pro.MainApplication
​     mBase instance of android.app.ContextImpl
@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@sam-gc
Copy link
Contributor

sam-gc commented Feb 1, 2021

Hi, thanks for reaching out. I've filed a bug internally for tracking. (b/179034484)

@mikezliu
Copy link

Is there any ETA for a fix or an older version we can revert to? I'm getting a lot of memory leak reports from leakcanary for this issue

@csechuan
Copy link

csechuan commented Apr 14, 2021

[READ] Step 1: Are you in the right place?

yes

[REQUIRED] Step 2: Describe your environment

Android Studio version: 4.2 Beta 6
Firebase Component: Firebase Authentication
Component version: 20.0.4

[REQUIRED] Step 3: Describe the problem

LeakCanary is telling me that "FirebaseAuthFallbackService " is leaking.
Just add the firebase bom and firebase auth. Run the app with leak canary enabled, and bring the app to background.

Steps to reproduce:

  1. Create a new project
  2. Add leakcanary, firebase bom and firebase-auth lib
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
    implementation platform('com.google.firebase:firebase-bom:27.0.0')
    implementation 'com.google.firebase:firebase-auth-ktx'
  3. Run the app, click home button (or whatever it takes to bring the app to background).
  4. For a short while, leak canary will report a leak as attached below.

Relevant Code:
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS

References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.

1325 bytes retained by leaking objects
Signature: d7eca9435653e8afa0dd1f85b3ecd43847de7e26
┬───
│ GC Root: Global variable in native code
│
├─ com.google.firebase.auth.api.fallback.service.zza instance
│    Leaking: UNKNOWN
│    Retaining 1.9 kB in 10 objects
│    zza instance of com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
│    ↓ zza.zza
│          ~~~
╰→ com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService instance
​     Leaking: YES (ObjectWatcher was watching this because com.google.firebase.auth.api.fallback.service.
​     FirebaseAuthFallbackService received Service#onDestroy() callback and Service not held by ActivityThread)
​     Retaining 1.3 kB in 9 objects
​     key = 0926f4f3-852f-465d-9f35-79c785261aae
​     watchDurationMillis = 5129
​     retainedDurationMillis = 125
​     mApplication instance of com.example.MainApplication
​     mBase instance of android.app.ContextImpl
====================================
0 LIBRARY LEAKS

A Library Leak is a leak caused by a known bug in 3rd party code that you do not have control over.
See https://square.github.io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
====================================
0 UNREACHABLE OBJECTS

An unreachable object is still in memory but LeakCanary could not find a strong reference path
from GC roots.
====================================
METADATA

Please include this in bug reports and Stack Overflow questions.

Build.VERSION.SDK_INT: 30
Build.MANUFACTURER: Google
LeakCanary version: 2.7
App process name: com.example
Stats: LruCache[maxSize=3000,hits=2124,misses=61170,hitRate=3%]
RandomAccess[bytes=2972109,reads=61170,travel=22600881259,range=18406153,size=24436593]
Heap dump reason: 1 retained objects, app is not visible
Analysis duration: 5421 ms
Heap dump file path: /storage/emulated/0/Download/leakcanary-com.example/2021-04-15_00-36-43_029.hprof
Heap dump timestamp: 1618418210378
Heap dump duration: 1867 ms
====================================

@mj8894
Copy link

mj8894 commented Jun 1, 2021

Hi,

I am getting the same issue in my application too. Is there any fix to prevent this from leaking?

@nikhiljainlive
Copy link

I am also facing this issue. Any fixes?

@KORuL
Copy link

KORuL commented Jul 3, 2021

I am also facing this issue.

@nikhiljainlive
Copy link

I am getting this issue frequently whenever I am exiting the app or going into the background from my app.
Refer below for heap analysis result:

====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS

References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.

1533 bytes retained by leaking objects
Signature: d7eca9435653e8afa0dd1f85b3ecd43847de7e26
┬───
│ GC Root: Global variable in native code
│
├─ com.google.firebase.auth.api.fallback.service.zza instance
│    Leaking: UNKNOWN
│    Retaining 2.1 kB in 10 objects
│    zza instance of com.google.firebase.auth.api.fallback.service.
│    FirebaseAuthFallbackService
│    ↓ zza.zza
│          ~~~
╰→ com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
​  instance
​     Leaking: YES (ObjectWatcher was watching this because com.google.firebase.
​     auth.api.fallback.service.FirebaseAuthFallbackService received
​     Service#onDestroy() callback and Service not held by ActivityThread)
​     Retaining 1.5 kB in 9 objects
​     key = b30e018a-f7f7-46a2-8195-64a7c1c73d6d
​     watchDurationMillis = 5251
​     retainedDurationMillis = 245
​     mApplication instance of com.nikhiljain.fundoonotes.MyApplication
​     mBase instance of android.app.ContextImpl
====================================
0 LIBRARY LEAKS

A Library Leak is a leak caused by a known bug in 3rd party code that you do
not have control over.
See https://square.github.
io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
====================================
0 UNREACHABLE OBJECTS

An unreachable object is still in memory but LeakCanary could not find a strong
reference path
from GC roots.
====================================
METADATA

Please include this in bug reports and Stack Overflow questions.

Build.VERSION.SDK_INT: 30
Build.MANUFACTURER: samsung
LeakCanary version: 2.7
App process name: com.nikhiljain.fundoonotes
Stats: LruCache[maxSize=3000,hits=3845,misses=86152,hitRate=4%]
RandomAccess[bytes=3983274,reads=86152,travel=69821486786,range=36820301,size=47
266607]
Heap dump reason: 1 retained objects, app is not visible
Analysis duration: 12396 ms
Heap dump file path: /storage/emulated/0/Download/leakcanary-com.nikhiljain.
fundoonotes/2021-07-04_21-31-03_017.hprof
Heap dump timestamp: 1625414484796
Heap dump duration: 9336 ms
====================================

Is there any progress on the fix of this issue?

@mikezliu
Copy link

mikezliu commented Jul 4, 2021

I heard that they will assign this to a software engineer intern in summer of 2035

@pyricau
Copy link

pyricau commented Jul 9, 2021

The Firebase team should definitely fix this bug in FirebaseAuthFallbackService.

In the meantime, here's how you can configure LeakCanary to stop tracking FirebaseAuthFallbackService:

First, disable the automatic install:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <bool name="leak_canary_watcher_auto_install">false</bool>
</resources>

Then install LeakCanary manually in your debug application, ignoring FirebaseAuthFallbackService:

class DebugExampleApplication : ExampleApplication() {

  override fun onCreate() {
    super.onCreate()

    val delegate = ReachabilityWatcher { watchedObject, description ->
      if (watchedObject::class.java.name != "com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
​  instance") {
        AppWatcher.objectWatcher.expectWeaklyReachable(watchedObject, description)
      }
    }

    val watchersToInstall = AppWatcher.appDefaultWatchers(application, delegate)

    AppWatcher.manualInstall(
      application = application,
      watchersToInstall = watchersToInstall
    )
  }
}

@namgk
Copy link

namgk commented Jul 13, 2021

@pyricau silencing it is easy, but more important is, does it lead to app crash?

We run 24/7 kiosk application and ours crash once in a while. We're trying to figure it out :(

@mwshubham
Copy link

+1

@remvst
Copy link

remvst commented Jul 14, 2021

Also seeing this issue, which causes our team to check leaks less often, since they all assume it's this specific leak we can't do anything about.

Would love to see it fixed on the firebase side

@Brian605
Copy link

This issue is Causing ANR in my app

@lincolnthree
Copy link

Also getting ANRs from this.

@ChrisKruegerDev
Copy link

+1

@Chani91
Copy link

Chani91 commented Aug 20, 2021

@Brian605 Have you come up with a fair solution?

@rafiqlightwala
Copy link

Someone from the firebase team should look into this urgently!

@Jack29913
Copy link

Hey firebase team will you address this issue? We are getting tons of ANR's because of this!
@vkryachko @schmidt-sebastian

@nahuelb
Copy link

nahuelb commented Aug 31, 2021

+1

@alex-kurd
Copy link

+1, Please fix that issue. We have a lot of ANRs in the app because of that.

@Toubap
Copy link

Toubap commented Sep 1, 2021

Still not fixed.. 😢

@vkryachko
Copy link
Member

Hey folks, sorry that it's taking this long. I've forwarded this issue to the Auth team, there is an internal bug tracking progress for this. cc @malcolmdeck

Thanks for your patience.

@johndoe457
Copy link

Why did this issue suddenly get traffic?
I didn't think it would help, but it seems like it does :)

@wangyongchao
Copy link

Cause a lot of anr, the version can’t be sent out

@xiaolong125
Copy link

+1

1 similar comment
@JoniGoos
Copy link

+1

@artakka
Copy link

artakka commented Nov 30, 2021

Hope this gets fixed soon

@forceporquillo
Copy link

+1

1 similar comment
@rranjithkumar100
Copy link

+1

@thias15
Copy link

thias15 commented Dec 21, 2021

+1

1 similar comment
@lincolnthree
Copy link

+1

@pyricau
Copy link

pyricau commented Dec 21, 2021

I'm just going to leave this here: https://twitter.com/Piwai/status/1473315039188762632

😉

@dvdhfnr
Copy link

dvdhfnr commented Dec 22, 2021

This issue seems to also cause other memory leaks that seem to be totally unrelated at first glance; see #3236.

@rustycamper
Copy link

Today is Jan 1, 2022, the issue was reported on Jan 31, 2021...

@mkocus
Copy link

mkocus commented Jan 11, 2022

It seems that I have probably more information about this issue, which I have described in #3300.

It looks that it can happen when upgrading libraries. In our environment we used following versions:

implementation 'com.google.firebase:firebase-crashlytics:18.0.1'
implementation 'com.google.firebase:firebase-config-ktx:20.0.2'
implementation 'com.google.firebase:firebase-dynamic-links-ktx:19.1.1'
implementation 'com.google.firebase:firebase-analytics-ktx:18.0.1'

which has been lately upgraded (+ added database/auth) to BoM format:

implementation platform('com.google.firebase:firebase-bom:29.0.3')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-config-ktx'
implementation 'com.google.firebase:firebase-dynamic-links-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-database-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'

After running the new app, it looks that Firebase Crashlytics tries to read some files which are no longer there:

2022-01-11 11:47:10.687 3968-4436/<our_package> E/FirebaseCrashlytics: Could not open log file: /data/user/0/<our_package>/files/.com.google.firebase.crashlytics.files.v1/open-sessions/60EEC7AE028D00010F808FBD31139444/userlog
    java.io.FileNotFoundException: /data/user/0/<our_package>/files/.com.google.firebase.crashlytics.files.v1/open-sessions/60EEC7AE028D00010F808FBD31139444/userlog.tmp: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:485)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:288)
        at com.google.firebase.crashlytics.internal.log.QueueFile.open(QueueFile.java:221)
        at com.google.firebase.crashlytics.internal.log.QueueFile.initialize(QueueFile.java:202)
        at com.google.firebase.crashlytics.internal.log.QueueFile.<init>(QueueFile.java:117)
        at com.google.firebase.crashlytics.internal.log.QueueFileLogStore.openLogFile(QueueFileLogStore.java:128)
        at com.google.firebase.crashlytics.internal.log.QueueFileLogStore.writeToLog(QueueFileLogStore.java:52)
        at com.google.firebase.crashlytics.internal.log.LogFileManager.writeToLog(LogFileManager.java:64)
        at com.google.firebase.crashlytics.internal.common.CrashlyticsController$5.call(CrashlyticsController.java:387)
        at com.google.firebase.crashlytics.internal.common.CrashlyticsController$5.call(CrashlyticsController.java:383)
        at com.google.firebase.crashlytics.internal.common.CrashlyticsBackgroundWorker$3.then(CrashlyticsBackgroundWorker.java:105)
        at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@18.0.1:3)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:64)
        at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:27)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Linux.open(Native Method)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:210)
        at libcore.io.IoBridge.open(IoBridge.java:471)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:288) 
        at com.google.firebase.crashlytics.internal.log.QueueFile.open(QueueFile.java:221) 
        at com.google.firebase.crashlytics.internal.log.QueueFile.initialize(QueueFile.java:202) 
        at com.google.firebase.crashlytics.internal.log.QueueFile.<init>(QueueFile.java:117) 
        at com.google.firebase.crashlytics.internal.log.QueueFileLogStore.openLogFile(QueueFileLogStore.java:128) 
        at com.google.firebase.crashlytics.internal.log.QueueFileLogStore.writeToLog(QueueFileLogStore.java:52) 
        at com.google.firebase.crashlytics.internal.log.LogFileManager.writeToLog(LogFileManager.java:64) 
        at com.google.firebase.crashlytics.internal.common.CrashlyticsController$5.call(CrashlyticsController.java:387) 
        at com.google.firebase.crashlytics.internal.common.CrashlyticsController$5.call(CrashlyticsController.java:383) 
        at com.google.firebase.crashlytics.internal.common.CrashlyticsBackgroundWorker$3.then(CrashlyticsBackgroundWorker.java:105) 
        at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@18.0.1:3) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:64) 
        at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:27) 
        at java.lang.Thread.run(Thread.java:764) 

it tries to do that many times per second through 20s+ which basically hammers the app and gives ANR later.

This only happens directly after library upgrade.

@yoyomyo
Copy link

yoyomyo commented Jan 18, 2022

As Malcolm mentioned in the comment, we have an on-going refactoring. We will update this thread once we test the refactoring and get it ready for release.

@maclne
Copy link

maclne commented Jan 21, 2022

@yoyomyo thanks for working on the fix! I'm curious if there is an ETA for a fix for this as I am struggling to get around this and it's a show stopper for my app.

@yoyomyo
Copy link

yoyomyo commented Jan 26, 2022

After @malcolmdeck finished the refactoring, I am able to verify that the memory leak is no longer reproducible in the latest firebase-auth pre-release library. Will follow up here when the release goes out.

@mohitrajput-trell
Copy link

Is there any update on this issue? Which Firebase library version has fix of this issue?

@lincolnthree
Copy link

Echoing @mohitrajput-trell - I'd love to test a patched build of this if information is forthcoming :)

@mohitrajput-trell
Copy link

Echoing @mohitrajput-trell - I'd love to test a patched build of this if information is forthcoming :)

Here are the logs from Leak Canary:

2022-02-03 14:25:54.592 27201-27201/app.trell D/LeakCanary: ​
    ┬───
    │ GC Root: Global variable in native code
    │
    ├─ com.google.firebase.auth.api.fallback.service.zza instance
    │    Leaking: UNKNOWN
    │    Retaining 1.7 kB in 10 objects
    │    zza instance of com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
    │    ↓ zza.zza
    │          ~~~
    ╰→ com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService instance
    ​     Leaking: YES (ObjectWatcher was watching this because com.google.firebase.auth.api.fallback.service.
    ​     FirebaseAuthFallbackService received Service#onDestroy() callback and Service not held by ActivityThread)
    ​     Retaining 1.2 kB in 9 objects
    ​     key = 9b6a34ba-a272-4901-adc0-932f6a7995c3
    ​     watchDurationMillis = 5482
    ​     retainedDurationMillis = 464
    ​     mApplication instance of app.geochat.revamp.application.Trell
    ​     mBase instance of android.app.ContextImpl

    METADATA

    Build.VERSION.SDK_INT: 29
    Build.MANUFACTURER: HMD Global
    LeakCanary version: 2.8.1
    App process name: app.trell
    Stats: LruCache[maxSize=3000,hits=46061,misses=122358,hitRate=27%]
    RandomAccess[bytes=5690095,reads=122358,travel=45275876053,range=26961523,size=33003154]
    Analysis duration: 12699 ms

SDKs Version:

// Firebase
    implementation platform('com.google.firebase:firebase-bom:29.0.3')
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-config'
    implementation 'com.google.firebase:firebase-appindexing'
    implementation 'com.google.firebase:firebase-perf'

Let me know if you still want to customized APK for this.

@maclne
Copy link

maclne commented Feb 14, 2022

There was a new 29.1.0 BOM, however I don't see this fix mentioned and I am still getting the crash/ANR. @malcolmdeck and @yoyomyo, can either of you confirm whether or not this fix made it into that release?

@yoyomyo
Copy link

yoyomyo commented Feb 15, 2022

The fix is not in 29.1.0 yet. Please be patient, as the BOM testing and release process can take some time. We will update this thread as soon as we have more details.

@DidahDx
Copy link

DidahDx commented Feb 23, 2022

I'm facing the same issue

@ChrisKruegerDev
Copy link

I have also this issue in 29.1.0.

@joaoppedrosa
Copy link

joaoppedrosa commented Mar 3, 2022

@yoyomyo Can you please give an estimation of the time frame that you expect to have a version with this problem fix, days, weeks or months?
Because we have solutions that depended on this issue being fix, and this problem is making apps not working on some devices and get bad reviews because of it, and we need to know if we need to find a workaround or wait for a fix

@argzdev
Copy link
Contributor

argzdev commented Mar 17, 2022

Hi all, thank you for your patience! The fix is finally out in Firebase Authentication version 21.0.2. You may check out the release notes here. With that said, I'll be closing this issue now. Feel free to open a new issue if there are any other concerns or questions. Thanks!

@argzdev argzdev closed this as completed Mar 17, 2022
@maclne
Copy link

maclne commented Mar 17, 2022

Hi all, thank you for your patience! The fix is finally out in Firebase Authentication version 21.0.2. You may check out the release notes here. With that said, I'll be closing this issue now. Feel free to open a new issue if there are any other concerns or questions. Thanks!

This release fixed the startup issues I was having with our new app. Thanks for your hard work!

@firebase firebase locked and limited conversation to collaborators Apr 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests