Skip to content

onCancel not called on permission error #28

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

Closed
yh1224 opened this issue Sep 19, 2018 · 3 comments
Closed

onCancel not called on permission error #28

yh1224 opened this issue Sep 19, 2018 · 3 comments
Assignees
Labels
api: database type: bug Something isn't working

Comments

@yh1224
Copy link

yh1224 commented Sep 19, 2018

Environment

  • Android Studio version: 3.2 RC3
  • Firebase Component: Database
  • Component version: 16.0.2 / 11.8.0

Problem

addListener to the reference which has no permissions, then
onCancel will be called with DatabaseError: Permission denied.

But adding more than two listeners to the same reference with and without orderBy,
onCancel called for only listeners with orderBy, not for listeners without orderBy.

Steps to reproduce:

val ref = FirebaseDatabase.getInstance().getReference("test")
ref.orderByKey().addListenerForSingleValueEvent(...)  -> called
ref.addListenerForSingleValueEvent(...)  -> not called
ref.orderByKey().addValueEventListener(...)  -> called
ref.addValueEventListener(...)  -> not called
ref.orderByKey().addChildEventListener(...)  -> called
ref.addChildEventListener(...)  -> not called

Add listeners by different order, then onCancel called for all listeners.

val ref = FirebaseDatabase.getInstance().getReference("test")
ref.addListenerForSingleValueEvent(...)  -> called
ref.orderByKey().addListenerForSingleValueEvent(...)  -> called
ref.addValueEventListener(...)  -> called
ref.orderByKey().addValueEventListener(...)  -> called
ref.addChildEventListener(...)  -> called
ref.orderByKey().addChildEventListener(...)  -> called
@schmidt-sebastian
Copy link
Contributor

Hi @yh1224, thanks for letting us know about this. We currently have a backlog of issues to work through, and will prioritize this accordingly. I suspect that this has something to do with our persistence cache, and all but one listener return results from cache. Please don't quote me on this until we verify this assumption though!

Thank you.

@mikelehen
Copy link
Contributor

FWIW I think the issue may be related to the fact that when we listen to a query, we'll treat a query that loads all data (even if it has an orderBy) as a "default" query (no query constraints, etc.):

I believe this means that the orderBy() and non-orderBy() queries will be de-duped into a single backend listen request.

But when we get a listen error and cancel the event registrations, we seem to treat orderBy and non-orderBy queries as distinct. This comment makes that sound intentional, but I don't understand why. It seems like it should match the other code. :-/

// A removal on a default query affects all queries at that location. A removal on an

So I think the fix is somewhere in that code, but given the complexity and age of this code it may be a semi-risky thing to mess with.

@schmidt-sebastian
Copy link
Contributor

Closing this due to inactivity. Please re-open if this is still an issue.

@firebase firebase locked and limited conversation to collaborators Jan 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: database type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants