Uncaught exception in Firebase runloop (3.0.0) related to persistence and queries
Asked Answered
P

2

2

I'm struggling with this exception for a while already. A relevant thread on the firebase group is kind of dead https://groups.google.com/forum/#!topic/firebase-talk/iy0762S3KsU, also two related on SO are unanswered: Uncaught exception in Firebase runloop (3.0.0) and Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected]

The workaround saying to switch off database persistence works, but it's not unacceptable for apps which require offline capability.

I've prepared a minimal activity example which reproduces the exception in my environment. It all comes down to reading the database with queries. It's enough to launch and terminate ("terminate" from Android Studio, not just quit) the activity 3 times (weird) and on the 3rd launch it will crash with the following spectacular series of exceptions (the more queries queued the more exceptions i think):

07-05 18:47:10.132 20291-20291/com.mypackage D/ChimeraFileApk: Classloading successful. Optimized code found.
07-05 18:47:10.154 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected]
                                                           java.lang.AssertionError: hardAssert failed: 
                                                               at com.google.android.gms.internal.zzaiv.zzb(Unknown Source)
                                                               at com.google.android.gms.internal.zzaiv.zzaN(Unknown Source)
                                                               at com.google.android.gms.internal.zzagh.zzb(Unknown Source)
                                                               at com.google.android.gms.internal.zzagh.<init>(Unknown Source)
                                                               at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                               at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                               at com.google.android.gms.internal.zzadp.zza(Unknown Source)
                                                               at com.google.android.gms.internal.zzaeu.zzic(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zzRy(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zza(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc$1.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.154 20291-20291/com.mypackage D/AndroidRuntime: Shutting down VM
07-05 18:47:10.155 20291-20291/com.mypackage E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.mypackage, PID: 20291
                                                                  java.lang.RuntimeException: Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected]
                                                                      at com.google.android.gms.internal.zzadp$1$1.run(Unknown Source)
                                                                      at android.os.Handler.handleCallback(Handler.java:739)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                   Caused by: java.lang.AssertionError: hardAssert failed: 
                                                                      at com.google.android.gms.internal.zzaiv.zzb(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaiv.zzaN(Unknown Source)
                                                                      at com.google.android.gms.internal.zzagh.zzb(Unknown Source)
                                                                      at com.google.android.gms.internal.zzagh.<init>(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                                      at com.google.android.gms.internal.zzadp.zza(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaeu.zzic(Unknown Source)
                                                                      at com.google.android.gms.internal.zzafc.zzRy(Unknown Source)
                                                                      at com.google.android.gms.internal.zzafc.zza(Unknown Source)
                                                                      at com.google.android.gms.internal.zzafc$1.run(Unknown Source)
                                                                      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                      at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.165 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected]
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.google.android.gms.internal.zzafj.zzg(com.google.android.gms.internal.zzaew)' on a null object reference
                                                               at com.google.android.gms.internal.zzafc.zzf(Unknown Source)
                                                               at com.google.firebase.database.Query$3.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.166 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected]
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.google.android.gms.internal.zzafj.zzg(com.google.android.gms.internal.zzaew)' on a null object reference
                                                               at com.google.android.gms.internal.zzafc.zzf(Unknown Source)
                                                               at com.google.firebase.database.Query$3.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.173 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected]
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.internal.zzafg.zzg(com.google.android.gms.internal.zzafa, com.google.android.gms.internal.zzahu)' on a null object reference
                                                               at com.google.android.gms.internal.zzafc.zzb(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zza(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zzaO(Unknown Source)
                                                               at com.google.firebase.database.connection.idl.IPersistentConnectionImpl$3.zzaO(Unknown Source)
                                                               at com.google.firebase.database.connection.idl.zzi$zza.onTransact(Unknown Source)
                                                               at android.os.Binder.transact(Binder.java:387)
                                                               at alx.a(:com.google.android.gms.DynamiteModulesC:196)
                                                               at amb.a(:com.google.android.gms.DynamiteModulesC:330)
                                                               at akh.a(:com.google.android.gms.DynamiteModulesC:3591)
                                                               at amf.a(:com.google.android.gms.DynamiteModulesC:386)
                                                               at aln.onTransact(:com.google.android.gms.DynamiteModulesC:50)
                                                               at android.os.Binder.transact(Binder.java:387)
                                                               at com.google.firebase.database.connection.idl.zzf$zza$zza.zzhT(Unknown Source)
                                                               at com.google.firebase.database.connection.idl.IPersistentConnectionImpl$5$1.zzhT(Unknown Source)
                                                               at com.google.android.gms.internal.zzaeu$1$1.zzhT(Unknown Source)
                                                               at com.google.android.gms.internal.zzadn$1.onFailure(Unknown Source)
                                                               at com.google.android.gms.tasks.zzd$1.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:11.745 20291-20291/com.mypackage I/Process: Sending signal. PID: 20291 SIG: 9

The crash is on the first attempt to read after getting the reference to the database and setting persistence is done.

Here's the activity:

public class TestRunloopException extends AppCompatActivity {

    private static final String TAG = "test";
    private Handler mHandler = new Handler();

    Runnable mReadScoresRunnable = new Runnable() {
        @Override
        public void run() {
            readScores();
            mHandler.postDelayed(mReadScoresRunnable, 5000);
        }
    };

    @Override
    protected void onStart() {
        super.onStart();
        mHandler.postDelayed(mReadScoresRunnable, 3000);
    }

    void readScores() {
        DatabaseReference scoresRef = getDatabase().getReference("scores");
       //it occurs even with a single query..
       //scoresRef.startAt(51).limitToFirst(3).addListenerForSingleValueEvent(new MyValueListener());
        scoresRef.endAt(50).limitToLast(4).addListenerForSingleValueEvent(new MyValueListener());
    }


    public static class MyValueListener implements ValueEventListener {
        @Override
        public void onDataChange(DataSnapshot data) {
            Log.d(TAG, "onDataChange: " + data.getValue());
        }

        @Override
        public void onCancelled(DatabaseError error) {
            Log.d(TAG, "onCancelled: " + error.getMessage());
        }
    }


    // access-wrapper, set persistence only once
    private static FirebaseDatabase mDatabase;
    public static FirebaseDatabase getDatabase() {
        if (mDatabase == null) {
            mDatabase = FirebaseDatabase.getInstance();
            mDatabase.setPersistenceEnabled(true);
        }
        return mDatabase;
    }

}

The "scores" node has no particular security settings: "scores": { ".read": true, ".write": true } ...

Tested with firebase-*:9.0.2, but the bug has been also observed with 9.2.0.

How to avoid the crash while using multiple queries on the same reference/node and of course having persistence?

Princeling answered 5/7, 2016 at 17:1 Comment(1)
See on this thread github.com/firebase/quickstart-android/issues/45Rhodic
G
0

The only solution that worked for me is calling the Event Listener twice back to back.

scoresRef.endAt(50).limitToLast(4).addListenerForSingleValueEvent(new MyValueListener());
scoresRef.endAt(50).limitToLast(4).addListenerForSingleValueEvent(new MyValueListener());
Gastrula answered 9/2, 2019 at 18:32 Comment(0)
C
0

I had the same problem, i just fixed updating a version of firebase-core and firebase-database on build.gradle (app module)

dependencies {
  ... 
  implementation 'com.google.firebase:firebase-core:17.1.0'
  implementation 'com.google.firebase:firebase-database:19.0.0'
}

you can check if you have i current version on https://firebase.google.com/support/release-notes/android

Cotemporary answered 21/8, 2019 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.