Skip to content

[firebase_database]: FirebaseDatabasePlugin.removeEventStreamHandlers java.util.ConcurrentModificationException #17875

@Tom3652

Description

@Tom3652

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Database

Which platforms are affected?

Android

Description

Android crash using the latest version of firebase_database in release mode :

          Fatal Exception: java.lang.RuntimeException: Unable to destroy activity {com.behype.android/com.behype.android.MainActivity}
       at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:6321)
       at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:6353)
       at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:52)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleItem(TransactionExecutor.java:169)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:101)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2830)
       at android.os.Handler.dispatchMessage(Handler.java:110)
       at android.os.Looper.dispatchMessage(Looper.java:315)
       at android.os.Looper.loopOnce(Looper.java:251)
       at android.os.Looper.loop(Looper.java:349)
       at android.app.ActivityThread.main(ActivityThread.java:9041)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
                   Caused by java.util.ConcurrentModificationException:
       at java.util.HashMap$HashIterator.nextNode(HashMap.java:1603)
       at java.util.HashMap$EntryIterator.next(HashMap.java:1636)
       at java.util.HashMap$EntryIterator.next(HashMap.java:1634)
       at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin.removeEventStreamHandlers(FirebaseDatabasePlugin.kt:482)
       at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin.cleanup(FirebaseDatabasePlugin.kt:477)
       at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin.onDetachedFromEngine(FirebaseDatabasePlugin.kt:443)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:272)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:280)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:288)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:123)
       at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:509)
       at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:784)
       at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:921)
       at android.app.Activity.performDestroy(Activity.java:9549)
       at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1559)
       at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:6308)
       at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:6353)
       at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:52)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleItem(TransactionExecutor.java:169)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:101)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2830)
       at android.os.Handler.dispatchMessage(Handler.java:110)
       at android.os.Looper.dispatchMessage(Looper.java:315)
       at android.os.Looper.loopOnce(Looper.java:251)
       at android.os.Looper.loop(Looper.java:349)
       at android.app.ActivityThread.main(ActivityThread.java:9041)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
        

I have not tried to reproduce it myself but i have already dozen of crashes in production so i am pretty sure this is an "obvious" crash.

Here is the whole trace.txt

Reproducing the issue

  • According to the trace :
  1. register a listener
  2. kill the activity or close the listener

Firebase Core version

4.2.1

Flutter Version

3.38.3

Relevant Log Output

Flutter dependencies

Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: androidIssues / PRs which are specifically for Android.plugin: databaseresolution: fixedA fix has been merged or is pending merge from a PR.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions