Skip to content

Only run the provided delayed operation early #3101

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
May 26, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented May 22, 2020

The code to fast-forward the IndexedDB retries uses runDelayedOperationsEarly(), which runs not only the provided delayed operation, but all operations that were scheduled prior. This causes the OnlineStateTimer to run on page visibility events (see #2923).

Since Timer operations are likely not dependent on one another, it seems better to only run the provided operation. This also makes the API much less surprising.

Note that op.skipDelay() cannot be used directly in the visibility handler since we do not keep track of the DelayedOperation once it is scheduled via the backoff algorithm.

Fixes #2923

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 22, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (5ffa43b) Head (135a9d3) Diff
    browser 251 kB 251 kB +4 B (+0.0%)
    esm2017 195 kB 195 kB -27 B (-0.0%)
    main 493 kB 493 kB +51 B (+0.0%)
    module 249 kB 249 kB +4 B (+0.0%)
  • @firebase/firestore/memory

    Type Base (5ffa43b) Head (135a9d3) Diff
    browser 192 kB 192 kB +4 B (+0.0%)
    esm2017 149 kB 149 kB -27 B (-0.0%)
    main 369 kB 369 kB +51 B (+0.0%)
    module 190 kB 190 kB +4 B (+0.0%)
  • firebase

    Type Base (5ffa43b) Head (135a9d3) Diff
    firebase-firestore.js 290 kB 290 kB +5 B (+0.0%)
    firebase-firestore.memory.js 232 kB 232 kB +5 B (+0.0%)
    firebase.js 823 kB 823 kB +5 B (+0.0%)

Test Logs

* @returns a Promise that resolves once all operations have been run.
*/
runDelayedOperationsEarly(lastTimerId: TimerId): Promise<void> {
runDelayedOperationsEarly(timerId: TimerId): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks the intent of what this test-only method was for. The idea was that you could fast-forward time until the delayed operation ran, including anything scheduled prior to it. In this interface, now you have to know exactly what you want to run, which makes this a much less effective tool for testing. In particular, this makes it really hard to use this for spec tests because we're no longer simulating the actual passage of time, but merely jumping ahead to this specific event. This makes it far less likely that we'll catch scheduling-related problems with tests.

If we really need to allow a scheduled operation to run early, can't we add this as a method to the DelayedOperation?

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 updated the code to return DelayedOperation instead of CancellablePromise, and added a skipDelay to ExponentialBackoff.

I feel that we might even get rid of the TimerIds with this change, since we now have direct access to the underlying operations - but that of course would remove the ability to run delayed operations in order. It might drastically simplify this code though.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff May 26, 2020
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff May 26, 2020
@schmidt-sebastian schmidt-sebastian merged commit ea2fcf5 into master May 26, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/rundelayed branch May 26, 2020 21:07
@firebase firebase locked and limited conversation to collaborators Jun 26, 2020
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.

Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.----- react-native
3 participants