flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [cloud_firestore] `collectionGroup` using `get()` throws `[cloud_firestore/unavailable] The service is currently unavailable.`

Open Shawn-sudo opened this issue 3 years ago • 9 comments

Fetching documents using collectionGroup() throws "unavailable" error in certain circumstances.

This results in an error:

  1. Turn off wifi and cellular data (no internet connection) before the app is opened
  2. Launch the app
  3. Call FirebaseFirestore.instance.collectionGroup("helloo").where(abcde).limit(1234).get()
  4. [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.

Weirdly, if I do step 1. after doing 2. and 3. (2 --> 3 --> 1 --> ...), further collectionGroup(...).get() calls don't result in the error and gets docs from the cache as expected.

Shawn-sudo avatar Sep 02 '22 03:09 Shawn-sudo

  1. Turn off wifi and cellular data (no internet connection) before the app is opened

@Shawn-sudo Any network related operation / behavior is not likely to be a Flutterfire issue, because the plugin is a wrapper around native Firebase sdks and send, receive data through Dart.

I suggest you to raise this issue in underlying Firebase sdk (ios, web or android).

4. [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.

For this, please follow-up in similar / related discussion thread: https://github.com/firebase/flutterfire/discussions/5708

Closing from here. For network related behavior, if you get directed here, write in comments and I'll reopen this issue.

darshankawar avatar Sep 02 '22 11:09 darshankawar

@darshankawar Umm so hi again! I was trying to work it out at https://github.com/firebase/firebase-ios-sdk/issues/10164 , but we couldn't find a way to solve it. While hanging around there, I also tested it on Android with Flutter, and figured out that fetching documents from cache using collectionGroup query (no internet) also fails on Android. Just like on iOS, fetching documents from cache using collection query worked well. It was only collectionGroup query that didn't work. I'm not sure if collectionGroup offline fetching works well on native iOS and native Android, but since it didn't work on both platforms with flutter, I'm guessing that this is an issue of flutterfire.

Shawn-sudo avatar Sep 15 '22 12:09 Shawn-sudo

Thanks for feedback. Reopening.

darshankawar avatar Sep 16 '22 05:09 darshankawar

@Shawn-sudo Can you try below and see if it helps ?

get(GetOptions(source: Source.cache))

darshankawar avatar Sep 16 '22 09:09 darshankawar

@darshankawar No luck :/ I experienced the same error with the option set.

Shawn-sudo avatar Sep 19 '22 04:09 Shawn-sudo

@Shawn-sudo I tried the scenario and ran it on iOS device which gave me proper results without throwing the reported error.

  1. Firestore db setup:
Screenshot 2022-09-19 at 2 06 00 PM
  1. final Stream<QuerySnapshot> _usersStream = FirebaseFirestore.instance.collectionGroup('testCollection').where('1').limit(1).snapshots();

  2. Used it in StreamBuilder as below:

body: StreamBuilder<QuerySnapshot>(
        stream: _usersStream,
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        //  print(snapshot);
          if (snapshot.hasError) {
            return Text('wrong');
          }
          return ListView(
            children: snapshot.data!.docs.map((DocumentSnapshot document) {
              Map<String, dynamic> data = document.data()! as Map<String, dynamic>;
              return ListTile(
                title: Text(data['name'].toString()),
                subtitle: Text(data['uid'].toString()),
              );
            }).toList(),
          );
        },
      )
  1. Turned OFF cellular and wifi on the device and ran the app which gave me below result in UI:
Screenshot 2022-09-19 at 2 09 32 PM

Please try the same and see if it helps. I am on latest master version of the framework.

darshankawar avatar Sep 19 '22 08:09 darshankawar

@darshankawar No luck :/ I experienced the same error with the option set.

Also check if this helps https://github.com/firebase/flutterfire/issues/6076#issuecomment-1090035730

darshankawar avatar Sep 19 '22 11:09 darshankawar

Hi @darshankawar, thanks for your efforts!

You used collectionGroup.snapshot() while I used collectionGroup.get(). I wondered if .get() is the only case that causes this issue, so I tested it. I figured out that collectionGroup.get() fails while collectionGroup.snapshot() (realtime listening) succeeds when there's no internet connection.

Shawn-sudo avatar Sep 19 '22 20:09 Shawn-sudo

Thanks for the update. I see that using collectionGroup.get() shows the error as reported, but I am not sure if this would fall under client sdk or at native level.

Keeping this issue open and labeling for expected behavior for this scenario.

darshankawar avatar Sep 20 '22 12:09 darshankawar

I don't think this is only limited to collectionGroup queries. I don't have any collectinGroup queries and I'm getting the same error using iOS simulator. I'm using cloud_firestore 4.3.1.

This might not be relevant, but it happened after I switched from using Firestore emulator to an actual call.

loolooii avatar Jan 23 '23 11:01 loolooii

Update: Erase All Content and Settings... in Menu -> Device "solved" this problem for now. Could be a temporary solution. Nevertheless, should be looked at I guess.

loolooii avatar Jan 23 '23 12:01 loolooii

hey 👋 we have heavily reworked Cloud Firestore implementation, do you still experience this issue?

Lyokone avatar Nov 28 '23 14:11 Lyokone

Hey @Shawn-sudo. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Dec 07 '23 02:12 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@Shawn-sudo if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Dec 18 '23 02:12 google-oss-bot