-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Other
Which platforms are affected?
iOS
Description
When trying to query Firestore data on some iOS devices, I'm encountering this error:
The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff.
The strange thing is that it's constant; even with a backoff function implemented, the error persists. Furthermore, it only happens when I use specific combinations in my query, which is even stranger since it's the same code. I mean, if I use collection('app_setup').doc('features') it works, but if I use collection('app_setup').doc('status') it doesn't work and throws the error above.
The functions I'm using for the query are:
Future<T?> retry<T>(
Future<T?> Function() callback,
{
int maxRetries = 4,
Duration timeout = const Duration(seconds: 5),
}) async {
int retryCount = 0;
while (retryCount < maxRetries) {
try {
return await callback().timeout(timeout);
} on FirebaseException catch (e) {
if (e.code == 'unavailable') {
retryCount++;
int delay = 1 << retryCount;
await Future<void>.delayed(Duration(seconds: delay));
} else {
rethrow;
}
} on TimeoutException {
retryCount++;
}
}
return null;
}
Future<Map<String, dynamic>?> readFeatures() async {
DocumentReference<Map<String, dynamic>>? docRef = database
?.collection('app_setup')
.doc('features');
DocumentSnapshot<Map<String, dynamic>>? doc = await docRef?.get();
return doc?.data();
}
Future<Map<String, dynamic>?> readStatus() async {
DocumentReference<Map<String, dynamic>>? docRef = database
?.collection('app_setup')
.doc('status');
DocumentSnapshot<Map<String, dynamic>>? doc = await docRef?.get();
return doc?.data();
}
👍 Map<String, dynamic>? response = await ref
.read(appConstantsProvider.notifier)
.retry(readFeatures);
👎 Map<String, dynamic>? response = await ref
.read(appConstantsProvider.notifier)
.retry(readStatus);
Some logs
Flutter doctor
[✓] Flutter (Channel stable, 3.35.6, on macOS 26.2 25C56 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Xcode - develop for iOS and macOS (Xcode 26.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2025.2)
[✓] VS Code (version 1.106.3)
firebase_core: "4.2.1"
cloud_firestore: "6.1.0"
Reproducing the issue
basic flutter create and GoogleService-Info.plist
Firebase Core version
4.2.1
Flutter Version
3.35.6
Relevant Log Output
Flutter dependencies
No response
Additional context and comments
No response

