firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.77k stars 874 forks source link

Insufficient permissions error after the user is inactive for some time #7590

Open LanderBeeuwsaert opened 10 months ago

LanderBeeuwsaert commented 10 months ago

Operating System

Mine: Windows 11; but happens on Macs as well

Browser Version

Mine: Chrome ; but happens on all kinds of browsers of users

Firebase SDK Version

9.22.2 ; angularFire 7.6.1

Firebase SDK Product:

Analytics, AppCheck, Auth, Database, Firestore, Functions, Messaging, Performance, Storage

Describe your project's tooling

Angular + AngularFire + rxjs + Angular-cli

Describe the problem

This code shows how the user document that is stored in firestore is updated:

in authenticationService there is a line of code: this.authentication$ = authState(this.auth); that uses angularFire authState

image

the underlying function using angularFire docData

image

for a user (the same happens for many of our users) the logging looks like this:

image

so the user has the browser window open without actually using the application.

Because of the annoying "feature" of firestore to trigger connected documents every 30 minutes (and probably costing us a pretty penny) (also, see that it's not cleanly triggering every 30 minutes, it's very haphazardly), it's logged that the user document changed (but when we compare in the logging the 2 documents, it's clear the document didn't actually change).

And then, after an undeterminate amount of time, without a clear reason, suddenly together with such a new trigger firebase-js-sdk says there is a permissions error.

However logging makes clear there was actually no logout.

Steps and code to reproduce issue

See the code above. Reproduce: leave an amount of computers open for days and wake them up intermittently.

google-oss-bot commented 10 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

LanderBeeuwsaert commented 10 months ago

We have similar issues for other queries: FirebaseError: Missing or insufficient permissions: ["sheets"]=>[{"field":{"segments":["owner_email"],"offset":0,"len":1},"op":"==","value":{"stringValue":"**"}},{"field":{"segments":["valid_until"],"offset":0,"len":1},"op":">","value":{"timestampValue":"2023-05-30T07:56:56.941000000Z"}}] (this is a query where we add in the logging the query parameters). In the screenshot while the error happens we can see that there seems to be a disconnect from the network at that time:

image

We show this "connection lost" toast message on the realtime database triggering a disconnect:

image
tom-andersen commented 9 months ago

Thanks for the information. This will take a little longer to investigate.

LanderBeeuwsaert commented 9 months ago

@tom-andersen understandable, glad that it's getting attention. If we can help let us know. We can't reproduce consistently ourselves however but we could add something in the exception handler to gather more information if that would be useful.

LanderBeeuwsaert commented 9 months ago

One more indication it has something to do with loss of connection:

image

over a course of 40 seconds it keeps happening for this user on multiple subscribes while for that same user this is logged at the same time:

image

so the network connection seemed to be lost, 40 seconds later multiple subscriptions were being blocked with permissions denied, and then some time later the connection restored (and logging was written away)

LanderBeeuwsaert commented 8 months ago

Hi @tom-andersen , we still have +-20 instances of this issue every day. (on +- 500.000 reads/day) I'm 99% sure that this is something that all users using firestore have. Will it be possible to look into this somewhere in the coming ...? Just so to set expectations on if we'll have to learn to live with this or not?