Skip to content

Invoke RemoteStore's credential change listener even when user didn't change #4189

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

Merged
merged 3 commits into from
Dec 10, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Dec 10, 2020

This fixes an issue in the 8.0.2+ Firestore SDK, which only propagates user changes but not credential changes. This means that our WebChannel connection did not get reinitialized if a user ID didn't change, but the user's permission did.

If we get a user change notification, the correct behavior is:

  • Invoke the LocalStore's user change handler if the user changed. We should not invoke this handler if the user didn't change, because it is costly to reload the MutationQueue with IndexedDB and results in dataloss with memory persistence/
  • Always invoke the RemoteStore's credential change handler, since custom claims could have changed.

Verified using Sam's repro. Unfortunately, we don't have any testing infrastructure that automatically exercises this code.

Fixes #4175

@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2020

🦋 Changeset detected

Latest commit: 0c73ef1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/rules-unit-testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

if (!currentUser.isEqual(user)) {
currentUser = user;
client.asyncQueue.enqueueRetryable(async () => {
await handleUserChange(offlineComponentProvider.localStore, user);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the user change guard for LocalStore's handleUserChange here. It has always been part of the SyncEngine's call into LocalStore (https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/core/sync_engine.ts#L1084). This part of the code handles the user change when SyncEngine is not yet loaded (for a fully offline client).

I do however think that the guard here doesn't make a huge difference and mostly added it to be technically correct. This line of code is only executed when memory persistence is used without network access. The only sensible use case for this is an offline Firestore experience that is backed by Bundles. Bundles don't contain any mutations, so the user change would always be a no-op here. Once the user adds the first mutation, SyncEngine gets loaded and overwrites this listener.

I probably didn't describe this very well. But at least I tried, right? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not unreasonable to have here. The change is queued vs being immediately applied and also provides a tiny bit more predictability to the system.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 10, 2020

Size Analysis Report

Affected Products

No changes between base commit (566a62d) and head commit (fb49e84).

Test Logs

Copy link
Contributor

@rafikhan rafikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schmidt-sebastian and I discussed the nature of the change offline. LGTM.

if (!currentUser.isEqual(user)) {
currentUser = user;
client.asyncQueue.enqueueRetryable(async () => {
await handleUserChange(offlineComponentProvider.localStore, user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not unreasonable to have here. The change is queued vs being immediately applied and also provides a tiny bit more predictability to the system.

@schmidt-sebastian schmidt-sebastian merged commit 44b5251 into master Dec 10, 2020
@google-oss-bot google-oss-bot mentioned this pull request Dec 16, 2020
@firebase firebase locked and limited conversation to collaborators Jan 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firestore query uses stale token after forced refresh
3 participants