Skip to content
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

Firestore does not generate any callback/exception on attempting to upload data offline #565

Closed
AayushTaneja opened this issue Jul 18, 2018 · 4 comments

Comments

@AayushTaneja
Copy link

AayushTaneja commented Jul 18, 2018

Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository file a Github issue.
    • If you are filing an issue about FCM in the background make sure to read #4 and #89 first!
  • For general technical questions, post a question on StackOverflow tagged appropriately.
  • For general Firebase discussion, use the firebase-talk google group
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel

Step 2: Describe your environment

  • Android device: Xiaomi Mi A
  • Android OS version: 7.1
  • Google Play Services version: not sure
  • Firebase/Play Services SDK version: Firestore 17.0.3

Step 3: Describe the problem:

Firestore does not generate any callback/exception on attempting to upload data when device is offline. Hence, I am not able to alert the user to check their internet connection and retry.

Neither the onCompleteListener, nor the OnFailureListener callbacks get triggered.

Steps to reproduce:

Write code to upload data to firestore:

FirebaseFirestore.getInstance().collection("users").document("abcd").set(user).addOnCompleteListener(...).addOnFailureListener(...);

Run the app and turn off the internet connection.

Observed Results:

No callback/exception thrown

Expected Results:

onFailure callback or onComplete callback should be triggered and throw error or exception.

@samtstern
Copy link
Contributor

@AayushTaneja that's actually expected behavior. Those listeners only fire when the write has actually been written to the backend (or failed to do so). So when offline, they just never fire.

However when you write it's immediately written to the offline cache. So if you attach a snapshot listener to the location you're writing, you can get confirmation of the offline write that way (you'll get a DocumentSnapshot with the pending changes indicator set to true).

@Zedonboy
Copy link

Am making a get Query only AddOnSuccessListener get called, even when there is no network connection

@algrid
Copy link

algrid commented Oct 17, 2019

I have the same issue as @Zedonboy but when reading some data, not writing. How are we supposed to distinguish lack of connection vs real empty result received from server?

@samtstern
Copy link
Contributor

@algrid you can check:

querySnapshot.getMetadata().isFromCache()

That will tell you if the result is from the server or not (true means it's a local offline result).

https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/SnapshotMetadata.html#isFromCache()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants