firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.61k stars 3.95k forks source link

[Database/unavailable] Service unavailable on Android after update - Possible impact of multiple database support? #13186

Closed Alecia1997 closed 1 week ago

Alecia1997 commented 4 weeks ago

Is there an existing issue for this?

Which plugins are affected?

Database

Which platforms are affected?

No response

Description

Description:

We are encountering an issue with the cloud_firestore package where Android users are receiving the following error:

[cloud_firestore/unavailable] The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff.

Reproducing the issue

Steps to Reproduce: Update the cloud_firestore package to the latest version. Attempt to connect to a Firestore database from an Android device. The above error is received intermittently.

Expected Behavior: Android devices should be able to connect to the Firestore database without encountering the [cloud_firestore/unavailable] error.

Firebase Core version

^3.3.0

Flutter Version

3.24.0

Relevant Log Output

No response

Flutter dependencies

No response

Additional context and comments

No response

SelaseKay commented 4 weeks ago

Hi @Alecia1997 . Kindly provide a full sample code reproducing this issue.

Alecia1997 commented 4 weeks ago

Please find sample code to run:

import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';

class MainFirebaseRepository {
  final FirebaseFirestore _firebaseFirestore = FirebaseFirestore.instance;

  Future<int> latestAppVersion() async {
    try {
      DocumentSnapshot<Map<String, dynamic>> snapshot =
      await _firebaseFirestore.collection('settings').doc('latestAppVersion').get();

      if (Platform.isIOS) {
        return snapshot.data()?['iosBuild'] ?? 0;
      } else if (Platform.isAndroid) {
        return snapshot.data()?['androidBuild'] ?? 0;
      }
      return 0;
    } catch (e) {
      print('Error fetching latest app version: $e');
      rethrow;
    }
  }
}

class AppVersionChecker {
  final MainFirebaseRepository _repository = MainFirebaseRepository();

  Future<void> checkIfLatestAppVersion() async {
    try {
      PackageInfo packageInfo = await PackageInfo.fromPlatform();

      int buildNumberStoredInFirebase = await _repository.latestAppVersion();
      int myBuildNumber = int.tryParse(packageInfo.buildNumber) ?? 0;

      print('Firebase build number: $buildNumberStoredInFirebase');
      print('Current app build number: $myBuildNumber');

      if (buildNumberStoredInFirebase > myBuildNumber) {
        print('App not using latest version');
      } else {
        print('App is using latest version');
      }
    } catch (e) {
      print('Error checking app version: $e');
    }
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  AppVersionChecker checker = AppVersionChecker();
  await checker.checkIfLatestAppVersion();
}

The issue primarily impacts android users.

SelaseKay commented 4 weeks ago

I am unable to reproduce this issue locally on my end. This issue is similar to 12019. From previous reports, it seems to be related to network issue/firestore downtime, etc.

google-oss-bot commented 2 weeks ago

Hey @Alecia1997. 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 commented 1 week ago

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

@Alecia1997 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.