firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

[firebase_database] No implementation found for method cancel #13513

Open PhanVanLinh opened 3 days ago

PhanVanLinh commented 3 days ago

Is there an existing issue for this?

Which plugins are affected?

Messaging

Which platforms are affected?

Android

Description

This issue is similar to https://github.com/firebase/flutterfire/issues/7795, but the issue is closed. The crashlog in Firebase and Sentry is

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: MissingPluginException(No implementation found for method cancel on channel prices/ABC-[DEFAULT]-null-DatabaseEventType.value-[]#38). Error thrown .
at MethodChannel._invokeMethod(platform_channel.dart:332)
at EventChannel.receiveBroadcastStream.<fn>(platform_channel.dart:688)

We're using the Firebase database on a single screen with StreamBuilder, without much complex logic like

@override
Widget build(BuildContext context) {
  return StreamBuilder(
              stream: _databaseRef.child('prices').child(name).onValue,
              builder: (BuildContext context, snapshot) {
                  ...
              }
   };           
}

Currently, we can not reproduce the issue in development, but it's still happens to thousands users everyday. The issue mainly happens on Samsung device and Android 14 image

I have checked the FirebaseDatabasePlugin.java, Android create the channel and Flutter receive the channel from Android https://github.com/firebase/flutterfire/blob/main/packages/firebase_database/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java#L359

Android only remove in cleanUp https://github.com/firebase/flutterfire/blob/main/packages/firebase_database/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java#L601

And clean cleanUp is only get called when onDetachedFromEngine or didReinitializeFirebaseCore.

I think the above issue can only happens if onDetachedFromEngine or didReinitializeFirebaseCore get called before Stream get cancel but I don't know if it's possible or not. If you need more detailed information about the issue, I can add more data to the Sentry log and send it after the next release.

Reproducing the issue

We are unable to reproduce this issue; it happens randomly for users.

Firebase Core version

2.32.0

Flutter Version

3.24.0

Relevant Log Output

No response

Flutter dependencies

firebase_auth: ^4.20.0 firebase_core: ^2.32.0 firebase_messaging: ^14.9.4 firebase_database: ^10.5.7 firebase_crashlytics: ^3.5.7 firebase_remote_config: ^4.4.7

android targetSDK:34

Additional context and comments

No response

SelaseKay commented 2 days ago

Hi @PhanVanLinh , thanks for the report. Is this the entire log?

PhanVanLinh commented 1 day ago

@SelaseKay yes, this is the entire log. we can attach more information by intercepting this exception before sending it to Sentry/Firebase, but we don't know what additional info should include, as the crash line internally from platform_channel