flutterfire
flutterfire copied to clipboard
🐛 [cloud_firestore] `collectionGroup` using `get()` throws `[cloud_firestore/unavailable] The service is currently unavailable.`
Fetching documents using collectionGroup() throws "unavailable" error in certain circumstances.
This results in an error:
- Turn off wifi and cellular data (no internet connection) before the app is opened
- Launch the app
- Call
FirebaseFirestore.instance.collectionGroup("helloo").where(abcde).limit(1234).get() - [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.
- 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 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.
Thanks for feedback. Reopening.
@Shawn-sudo Can you try below and see if it helps ?
get(GetOptions(source: Source.cache))
@darshankawar No luck :/
I experienced the same error with the option set.
@Shawn-sudo I tried the scenario and ran it on iOS device which gave me proper results without throwing the reported error.
- Firestore db setup:
-
final Stream<QuerySnapshot> _usersStream = FirebaseFirestore.instance.collectionGroup('testCollection').where('1').limit(1).snapshots(); -
Used it in
StreamBuilderas 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(),
);
},
)
- Turned OFF cellular and wifi on the device and ran the app which gave me below result in UI:
Please try the same and see if it helps. I am on latest master version of the framework.
@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
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.
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.
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.
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.
hey 👋 we have heavily reworked Cloud Firestore implementation, do you still experience this issue?
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!
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.