Skip to content

Do not use recursive getToken() loop #3260

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
wants to merge 3 commits into from

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jun 23, 2020

There has been another user affected by #3222, so I am sending this out for review now. This reduced the change of a possible getToken loop if our token is invalid by just using the last received token.

Fixes #3222

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 23, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (46fd70b) Head (a2affb2) Diff
    browser 249 kB 249 kB +13 B (+0.0%)
    esm2017 195 kB 195 kB +19 B (+0.0%)
    main 474 kB 474 kB -29 B (-0.0%)
    module 246 kB 246 kB +13 B (+0.0%)
    react-native 195 kB 195 kB +19 B (+0.0%)
  • @firebase/firestore/exp

    Type Base (46fd70b) Head (a2affb2) Diff
    browser 189 kB 189 kB +17 B (+0.0%)
    main 467 kB 467 kB -29 B (-0.0%)
    module 189 kB 189 kB +17 B (+0.0%)
    react-native 189 kB 189 kB +17 B (+0.0%)
  • @firebase/firestore/lite

    Type Base (46fd70b) Head (a2affb2) Diff
    browser 64.5 kB 64.6 kB +17 B (+0.0%)
    main 141 kB 141 kB -29 B (-0.0%)
    module 64.5 kB 64.6 kB +17 B (+0.0%)
    react-native 64.6 kB 64.7 kB +17 B (+0.0%)
  • @firebase/firestore/memory

    Type Base (46fd70b) Head (a2affb2) Diff
    browser 187 kB 187 kB +13 B (+0.0%)
    esm2017 146 kB 146 kB +19 B (+0.0%)
    main 348 kB 348 kB -29 B (-0.0%)
    module 185 kB 185 kB +13 B (+0.0%)
    react-native 146 kB 146 kB +19 B (+0.0%)
  • @firebase/messaging

    Type Base (46fd70b) Head (a2affb2) Diff
    esm2017 23.2 kB 25.9 kB +2.68 kB (+11.5%)
    main 31.4 kB 34.6 kB +3.18 kB (+10.1%)
    module 30.9 kB 34.1 kB +3.17 kB (+10.2%)
  • firebase

    Type Base (46fd70b) Head (a2affb2) Diff
    firebase-firestore.js 288 kB 288 kB +13 B (+0.0%)
    firebase-firestore.memory.js 227 kB 227 kB +13 B (+0.0%)
    firebase-messaging.js 39.2 kB 40.9 kB +1.71 kB (+4.4%)
    firebase.js 821 kB 823 kB +1.73 kB (+0.2%)

Test Logs

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2020

🦋 Changeset is good to go

Latest commit: 71e52aa

We got this.

This PR includes changesets to release 10 packages
Name Type
@firebase/firestore Patch
firebase Patch
firebase-exp Patch
firebase-firestore-integration-test Patch
@firebase/testing Patch
firebase-browserify-test Patch
firebase-package-typings-test Patch
firebase-messaging-selenium-test Patch
firebase-typescript-test Patch
firebase-webpack-test 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

@schmidt-sebastian
Copy link
Contributor Author

FWIW, the newest user report is from a user that doesn't use Firestore.

Copy link
Contributor

@var-const var-const left a comment

Choose a reason for hiding this comment

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

FWIW, the newest user report is from a user that doesn't use Firestore.

It seems like this change might be beneficial and shouldn't make things worse, but I'll leave it to your judgment whether it should be merged.

// user, we can't be sure).
if (this.tokenCounter !== initialTokenCounter) {
if (this.lastToken) {
// If we received a new token while this callback was pending (via
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: what is the reason to prefer lastToken to tokenData here?

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 would like you to verify this - but I think this matches the previous behavior. If we receive a token update via our callback listener, we ignore the token that is returned from the getToken call.

FWIW, while I think this is the cleaner solution to our token handling, I think the risk of it probably means we should not merge it. After all, we now have evidence that the problem we are trying to solve also exists in at least one other place (and maybe only that place).

Maybe @wilhuff wants a distraction from his current work and take a peak as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason this is complicated is that we need to subscribe to auth to get notified when the identity changes, so that we can trigger user changes in the local store.

The reason we ignored the token in that callback was because when remote store wants to restart streams it it's going to trigger a call to getToken. This restart might happen significantly later, because there may not have been active streams when the identity changed.

The central question we need to answer is whether or not the token listener will call us before the current access token expires. If it does, it seems like we could just always use the token supplied by the token listener, no? If we did that this could be much simpler.

@schmidt-sebastian
Copy link
Contributor Author

Closing this for now.

@firebase firebase locked and limited conversation to collaborators Sep 17, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/gettokenloop branch November 9, 2020 22:36
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.

auth.onAuthStateChanged + firestore.onSnapshot cause infinite loop of calls to /token.
4 participants