Skip to content

🐛 [firebase_database][android] Throws [firebase_database/permission-denied] followed by MissingPluginException(No implementation found for method cancel on channel #7556

@deepak786

Description

@deepak786

Bug report

I'm facing a very weird issue with firebase_database: 9.0.3 on android.

  1. I'm logged in with firebase_auth.
FirebaseAuth.instance.currentUser != null;
  1. The main screen initState has a query value listener on the firebase database path.
  StreamSubscription? _streamSubs;

  @override
  void initState() {
    super.initState();
    _streamSubs =
        FirebaseDatabase.instance.ref('/users/123456').onValue.map((event) {
      return event.snapshot.value;
    }).listen((event) {
      // ...
    });
  }

  @override
  void dispose() {
    _streamSubs?.cancel();
    super.dispose();
  }
  1. I logged out.
FirebaseAuth.instance.signOut();
// navigate to login screen
  1. LoggedIn again without closing the app.
FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password);
// you can use any provider.
// navigate to main screen
  1. Now a new query value listener will be added to the same database path from initState see step 2.
  2. At this time you will see the database error from the previous/stale value listener.
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_database/permission-denied] Client doesn't have permission to access the desired data.
E/flutter (17301):
E/flutter (17301):
E/flutter (17301): #0      MethodChannelQuery.observe.<anonymous closure> (package:firebase_database_platform_interface/src/method_channel/method_channel_query.dart:65:21)
E/flutter (17301): #1      _invokeErrorHandler (dart:async/async_error.dart:43:24)
E/flutter (17301): #2      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:269:9)
E/flutter (17301): #3      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:157:13)
E/flutter (17301): #4      _rootRunBinary (dart:async/zone.dart:1452:47)
E/flutter (17301): #5      _CustomZone.runBinary (dart:async/zone.dart:1342:19)
E/flutter (17301): #6      _CustomZone.runBinaryGuarded (dart:async/zone.dart:1252:7)
E/flutter (17301): #7      _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:360:15)
E/flutter (17301): #8      _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:378:7)
E/flutter (17301): #9      _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:280:7)
E/flutter (17301): #10     _ForwardingStreamSubscription._addError (dart:async/stream_pipe.dart:128:11)
E/flutter (17301): #11     _ForwardingStream._handleError (dart:async/stream_pipe.dart:95:10)
E/flutter (17301): #12     _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:157:13)
E/flutter (17301): #13     _rootRunBinary (dart:async/zone.dart:1452:47)
E/flutter (17301): #14     _CustomZone.runBinary (dart:async/zone.dart:1342:19)
E/flutter (17301): #15     _CustomZone.runBinaryGuarded (dart:async/zone.dart:1252:7)
E/flutter (17301): #16     _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:360:15)
E/flutter (17301): #17     _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:378:7)
E/flutter (17301): #18     _DelayedError.perform (dart:async/stream_impl.dart:602:14)
E/flutter (17301): #19     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
E/flutter (17301): #20     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7)
E/flutter (17301): #21     _rootRun (dart:async/zone.dart:1420:47)
E/flutter (17301): #22     _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter (17301): #23     _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
E/flutter (17301): #24     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)
E/flutter (17301): #25     _rootRun (dart:async/zone.dart:1428:13)
E/flutter (17301): #26     _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter (17301): #27     _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
E/flutter (17301): #28     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)
E/flutter (17301): #29     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (17301): #30     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (17301):

Note:
The rules on the database path will allow accessing the data only if you are logged in.

{
  "rules": {
    "users":{
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
}

This issue was not with the firebase_database version up to 8.2.0.
This does not happen on other platforms such as iOS and the web even with version 9.0.3

is this correct behavior? how this will be solved?

Metadata

Metadata

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