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.68k stars 3.97k forks source link

firebase_remote_config: internal remote config fetch error #13524

Open HarithaMadhushanka opened 10 hours ago

HarithaMadhushanka commented 10 hours ago

Is there an existing issue for this?

Which plugins are affected?

Remote Config

Which platforms are affected?

iOS

Description

Issue Summary:

We are encountering a FirebaseException when calling the await remoteConfig.fetchAndActivate(); method within our Flutter app using the firebase_remote_config plugin (version 4.3.8). The exception details are as follows:

Code Snippet:

try {
  await remoteConfig.fetchAndActivate();
} on FirebaseException catch (e) {
    debugPrint('FirebaseException Caught:');
    debugPrint('Error Code: ${e.code}');
    debugPrint('Message: ${e.message}');
    debugPrint('Plugin: ${e.plugin}');
    debugPrint('Full Exception: $e');
    debugPrint('StackTrace: ${e.stackTrace}');
} catch (e) {
    debugPrint("FAIL" + e.toString());
}

Error Logs:

flutter: FirebaseException Caught:
flutter: Error Code: internal
flutter: Message: cancelled
flutter: Plugin: firebase_remote_config
flutter: Full Exception: [firebase_remote_config/internal] cancelled
flutter: StackTrace: null

For Reference (Screenshot when debugging):

image (1)

Issue Details

Upon investigating the issue, I noticed that a similar problem was previously reported and resolved in Issue #6196. In that case, the error code returned was 999, and a fix was implemented here, which retries the fetchAndActivate call if the error code is 999.

This fix is also present in the version (4.3.8) of the firebase_remote_config plugin that we are using. However, the issue we are encountering now returns a different error code (internal instead of 999), which causes the retry logic to be bypassed, and thus the fix does not work in our case.

Specifically, the retry logic checks if the error code is 999:

if (error.code == 999 && _fetchAndActivateRetry == false) {
  _fetchAndActivateRetry = true;
  [self fetchAndActivate:arguments withMethodCallResult:result];
} else {
  result.error(nil, nil, nil, error);
}

Since our error code is internal, this condition fails, and the retry logic is not triggered.

Request for Fix

Could you please look into this issue and consider updating the logic to account for error codes like internal or other potential error codes? Currently, the fix only handles the specific case for error code 999, but our issue seems to fall under a broader category of errors.

It would be helpful if the retry logic could be extended to handle internal or similar errors to prevent these fetch requests from being cancelled and allow the operation to complete successfully.

Flutter Doctor for reference:

[✓] Flutter (Channel stable, 3.7.12, on macOS 15.0.1 24A348 darwin-arm64, locale en-PH)
    • Flutter version 3.7.12 on channel stable at /Users/haritha/fvm/versions/3.7.12
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (1 year, 6 months ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/haritha/Library/Android/sdk
    • Platform android-34, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.94.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • iPhone (mobile) • 00008130-######### • ios          • iOS 18.0.1 22A3370
    • macOS (desktop)         • macos                     • darwin-arm64 • macOS 15.0.1 ###### darwin-arm64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Reproducing the issue

Firebase Core version

2.24.2

Flutter Version

3.24.3

Relevant Log Output

flutter: FirebaseException Caught:
    flutter: Error Code: internal
    flutter: Message: cancelled
    flutter: Plugin: firebase_remote_config
    flutter: Full Exception: [firebase_remote_config/internal] cancelled
    flutter: StackTrace: null

Flutter dependencies

Expand Flutter dependencies snippet
```yaml firebase_core: ^2.14.0 firebase_remote_config: ^4.3.8 ```

Additional context and comments

No response

SelaseKay commented 8 hours ago

Hi @HarithaMadhushanka , thanks for the report. I'm unable to reproduce this issue on the latest version of firebase_remote_config: 5.1.3. Can you update your version and try again?

HarithaMadhushanka commented 5 hours ago

Hi @HarithaMadhushanka , thanks for the report. I'm unable to reproduce this issue on the latest version of firebase_remote_config: 5.1.3. Can you update your version and try again?

This issue is being encountered intermittently.

I am using the firebase_remote_config version 4.3.8 in my mobile app. Unfortunately, I cannot upgrade my Flutter SDK version beyond 3.0.0 due to other plugins in my application that depend on a Flutter SDK version between ">=2.16.1 <3.0.0" (as specified in the pubspec.yaml).

However, I will try upgrading my firebase_remote_config version to 5.0.2 and see if that resolves the issue.

Upon reviewing the source code of the latest version (5.1.3), I noticed that the fetchAndActivate method has not changed compared to the version 4.3.8 code. However, I did notice some other differences in the FLTFirebaseRemoteConfigPlugin.m file.

I will add my update in this thread if version 5.0.2 resolves this issue. Thanks!