-
Notifications
You must be signed in to change notification settings - Fork 617
Query snapshots not updating after returning to foreground #3249
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
Comments
I found out that if you disable the cache:
You will get an exception - [cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff. But the internet is available and it happens only when coming back from foreground, |
@bswhite1 Can you please try to call (on firestore failed): |
@itaishalom I don't believe your issue is related to my issue. I am not getting failures or exceptions on connecting to firestore. |
@argzdev Unfortunately I do not have an example program that exhibits the behavior. I tried making one for a while, but was unsuccessful. Only seems to be easily reproducible in our production app. Currently running a test with some edits in the localStore and targetCache. |
Hi @bswhite1, thanks for the extra details. It is plausible that this could be an underlying issue with the native SDK, however given that we aren't able to test this with a minimal reproducible example with native android. It's hard to say where the issue lies. We'll keep this open while we investigate this further. |
@bswhite1 Thanks for for all these details. Can you answer some questions that will help determine if this is an SDK issue?
As I see it now, your cache seems to be going out of sync and not all data is correctly persisted. |
Thank you for sending the data over email. I suspect that the local query state goes out of sync because we clear the internal mapping for the query but not the resume information. Usually, this is not a problem as we restart the query right away, which then fixes our internal state. This does not happen here because the app is backgrounded. I think this PR fixes this issue: #3267 If you have time, it would be wonderful if you could verify this. |
Thanks. I will try it out as is from your PR. However, I wonder if we need to add .withLastLimboFreeSnapshotVersion(SnapshotVersion.NONE); to the newTargetData |
I suspect that you are right. I will update the PR. |
Describe your environment
Describe the problem
Issue first documented here: firebase/flutterfire#7323
Updated problem description:
When the app returns to the foreground after being in the background for several hours, the listeners for QuerySnapshots can return wrong data. It only returns updates to the collection that were made while the app was in the background, or new updates after it is returned to the foreground. Unchanged documents are not returned. A force close and restart of the app corrects the issue.
Current debug analysis:
As mentioned above, issue was seen in Firebase BoM 29.0.0, firestore: 24.0.0
Issue is still seen in master as of this commit: d0048fd
I have tracked the issue down to this series of events.
Starting with the log where the app is the background.
App is started up and logs look good.
App is sent to the background and appears to go to sleep.
Eventually it may wake up and log something like this
I do not get any other events or data past this point. Phone appears to go back to sleep
When the phone is turned on and app is brought back to foreground, the app gets restarted and this is what I log.
After some time, I receive the listener from the server.
If we reboot the app again. target cache has been repopulated, so initial snapshot has correct documents.
Questions:
Looking for some help to either point me in the direction of a fix, or places to add more debugging. This is the first time I have dug into this code, so an unfamiliar with it, and what the purpose of things are. My initial thought is to set lastLimboFreeSnapshotVersion to none but that seems to be read/set multiple places. Also not sure if that is the correct fix.
The text was updated successfully, but these errors were encountered: