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

[firebase_remote_config]: When restarting the app, onUpdateConfig stream subscription is not released. #12539

Closed nero-angela closed 7 months ago

nero-angela commented 7 months ago

Is there an existing issue for this?

Which plugins are affected?

Remote Config

Which platforms are affected?

iOS (I only tested in iOS)

Description

When restarting the app, the subscription to the onUpdateConfig stream of the previously registered RemoteConfig is not unsubscribed.

It doesn't matter in Release mode, but in the Dev environment, there are various problems encountered as onUpdatedConfig is called multiple times.

Related issue and PR

Reproducing the issue

Source Code

main.dart ```dart import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:flutter/material.dart'; import 'package:flutter_issue/firebase_options.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); runApp( const MaterialApp( home: HomePage(), ), ); } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State createState() => _HomePageState(); } class _HomePageState extends State { late final FirebaseRemoteConfig firebaseRemoteConfig; StreamSubscription? subscription; @override void initState() { super.initState(); firebaseRemoteConfig = FirebaseRemoteConfig.instance; firebaseRemoteConfig.fetchAndActivate(); subscription = firebaseRemoteConfig.onConfigUpdated.listen((event) { print(event.updatedKeys); }); } @override void dispose() { print("disposed"); subscription?.cancel(); super.dispose(); } @override Widget build(BuildContext context) { return const Scaffold(); } } ```

Reproducting Step

  1. Subscribe to RemoteConfig’s onConfigUpdated.
  2. Restart the app.
  3. Change the RemoteConfig value in the Firebase Console.
  4. The listener of onConfigUpdated is called multiple times.

Test environment

Video

https://github.com/firebase/flutterfire/assets/26322627/5921847d-d2ee-4c83-9d53-89d5d90bb4f2

Firebase Core version

2.27.0

Flutter Version

3.16.8

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
```yaml Dart SDK 3.2.5 Flutter SDK 3.16.8 flutter_issue 1.0.0+1 dependencies: - cupertino_icons 1.0.6 - firebase_core 2.27.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_remote_config 4.3.17 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] dev dependencies: - flutter_lints 2.0.3 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] transitive dependencies: - _flutterfire_internals 1.3.25 [collection firebase_core firebase_core_platform_interface flutter meta] - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - clock 1.1.1 - collection 1.18.0 - fake_async 1.3.1 [clock collection] - firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.11.5 [firebase_core_platform_interface flutter flutter_web_plugins js meta web] - firebase_remote_config_platform_interface 1.4.25 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.4.25 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - js 0.6.7 [meta] - lints 2.1.1 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.10.0 - path 1.8.3 - plugin_platform_interface 2.1.8 [meta] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - stack_trace 1.11.1 [path] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.6.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - vector_math 2.1.4 - web 0.3.0 ```

Additional context and comments

No response

TarekkMA commented 7 months ago

Hey @nero-angela, thanks for detailing the reproduction steps. I’ve successfully reproduced the bug and am currently working on a fix.