-
Notifications
You must be signed in to change notification settings - Fork 944
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
Conversation
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.' | ||
); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
packages/firestore/CHANGELOG.md
Outdated
- [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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
[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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[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.
[Roll-forward of c7e1ec9 (which was reviewed, submitted, and then reverted due to regression). The regression fix and added tests are in 3be0938]
@jdimond.
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.