Skip to content

Offline get() improvements. #1197

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 6 commits into from
Sep 5, 2018
Merged

Conversation

mikelehen
Copy link
Contributor

[Roll-forward of c7e1ec9 (which was reviewed, submitted, and then reverted due to regression). The regression fix and added tests are in 3be0938]

  1. Changed MAX_WATCH_STREAM_FAILURES to 1 per conversation with @wilhuff and
    @jdimond.
  2. Fixed a "race" where when a get() triggered a watch stream error, we'd
    restart the stream, then get() would remove its listener, and so we had no
    listener left once the watch stream was "opened". Without a listen to send
    we'd be stuck in Offline state (even though we should be Unknown whenever
    we have no listens to send), resulting in the next get() returning data
    from cache without even attempting to reach the backend.

Michael Lehenbauer added 3 commits August 17, 2018 10:00
1. Changed MAX_WATCH_STREAM_FAILURES to 1 per conversation with @wilhuff and
   @jdimond.
2. Fixed a "race" where when a get() triggered a watch stream error, we'd
   restart the stream, then get() would remove its listener, and so we had no
   listener left once the watch stream was "opened". Without a listen to send
   we'd be stuck in Offline state (even though we should be Unknown whenever
   we have no listens to send), resulting in the next get() returning data
   from cache without even attempting to reach the backend.
await firestore.disableNetwork();
await expect(docRef.get()).to.eventually.be.rejectedWith(
'Failed to get document because the client is offline.'
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This initial failing get() call existed in the android test and caught the regression, so I've added it to web as well. The rest of the test is unchanged except to use async/await.

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

- [fixed] Fixed an issue where the first `get()` call made after being offline
could incorrectly return cached data without attempting to reach the backend.
- [changed] Changed `get()` to only make 1 attempt to reach the backend before
returning cached data, potentially reducing delays while offline.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth noting here that the two attempts mechanism was a work around for a specific backend bug that's no longer in effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@@ -77,6 +77,7 @@ describeSpec('Remote store:', [], () => {
// Close before we get an ack, this should reset our pending
// target counts.
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, { fromCache: true })
// This should work now.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this comment means anymore now that we've raised the event above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hrm, yeah. TBH I don't know exactly what it was referring to before, so I just removed it.

@mikelehen mikelehen requested a review from davideast as a code owner September 5, 2018 19:20
mikelehen pushed a commit to firebase/firebase-ios-sdk that referenced this pull request Sep 5, 2018
[Port of firebase/firebase-js-sdk#1197]

1. Changed MAX_WATCH_STREAM_FAILURES to 1 per conversation with @wilhuff and
   @jdimond.
2. Fixed a "race" where when a get() triggered a watch stream error, we'd
   restart the stream, then get() would remove its listener, and so we had no
   listener left once the watch stream was "opened". Without a listen to send
   we'd be stuck in Offline state (even though we should be Unknown whenever
   we have no listens to send), resulting in the next get() returning data
   from cache without even attempting to reach the backend.
Copy link
Member

@davideast davideast left a comment

Choose a reason for hiding this comment

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

LGTM

@mikelehen mikelehen merged commit f30be09 into master Sep 5, 2018
@mikelehen mikelehen deleted the mikelehen/only-one-retry-with-fix branch September 5, 2018 20:40
mikelehen added a commit to firebase/firebase-ios-sdk that referenced this pull request Sep 6, 2018
[Port of firebase/firebase-js-sdk#1197]

1. Changed MAX_WATCH_STREAM_FAILURES to 1 per conversation with @wilhuff and
   @jdimond.
2. Fixed a "race" where when a get() triggered a watch stream error, we'd
   restart the stream, then get() would remove its listener, and so we had no
   listener left once the watch stream was "opened". Without a listen to send
   we'd be stuck in Offline state (even though we should be Unknown whenever
   we have no listens to send), resulting in the next get() returning data
   from cache without even attempting to reach the backend.
@firebase firebase locked and limited conversation to collaborators Oct 16, 2019
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.

4 participants