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.73k stars 3.98k forks source link

🐛 [firebase_messaging] subscribeToTopic blocs thread when no internet connection #11299

Closed kayumarie closed 1 year ago

kayumarie commented 1 year ago

Bug report

Describe the bug When invoking FirebaseMessaging.instance.subscribeToTopic/ FirebaseMessaging.instance.unsubscribeFromTopic` on device with no internet connection is blocks the thread indefinitely without throwing an error

Steps to reproduce

Steps to reproduce the behavior:

  1. Disable wifi and mobile networks on a device
  2. Invoke FirebaseMessaging.instance.subscribeToTopic/ FirebaseMessaging.instance.unsubscribeFromTopic`
  3. Notice this methods are blocking thread execution

Expected behavior

Throw an error instead of blocking

Sample project

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp();
  try {
    debugPrint("Subscribe to promo topic");
    await FirebaseMessaging.instance.subscribeToTopic('promo');
    debugPrint("This message should not be displayed if no internet connection is available");
  } catch (e) {
    debugPrint("This message should be displayed if no internet connection is available");
  }
}
danagbemava-nc commented 1 year ago

Hi @kayumarie, what platform(s) are you experiencing this bug on?

Please provide the output of flutter pub deps -- --style=compact & the output of flutter doctor -v.

Thank you

kayumarie commented 1 year ago

flutter pub deps -- --style=compact

➜  app git:(bug/firebase_messaging_blocks_thread) ✗ flutter pub deps --  --style=compact
Dart SDK 3.0.5
Flutter SDK 3.10.5
app 1.04.06+10406

dependencies:
- datadog_flutter_plugin 1.3.2 [flutter flutter_web_plugins js plugin_platform_interface json_annotation uuid meta]
- firebase_analytics 10.4.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 2.14.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 14.6.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_remote_config 4.2.3 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter]
- flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine]
- flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math]

dev dependencies:
- build_runner 2.4.5 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- flutter_lints 2.0.1 [lints]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- freezed 2.3.2 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation]
- integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service async boolean_selector characters clock collection fake_async file js matcher material_color_utilities meta source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math webdriver]
- json_serializable 6.6.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
- mocktail 0.3.0 [collection matcher test]

dependency overrides:
- build_runner_core 7.2.7 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml]
- logging 1.1.1

transitive dependencies:
- _fe_analyzer_shared 61.0.0 [meta]
- _flutterfire_internals 1.3.3 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 5.13.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- args 2.4.2
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- build 2.4.0 [analyzer async convert crypto glob logging meta package_config path]
- build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 4.0.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.2.0 [analyzer async build collection crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- built_collection 5.1.1
- built_value 8.6.1 [built_collection collection fixnum meta]
- characters 1.3.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- clock 1.1.1
- code_builder 4.5.0 [built_collection built_value collection matcher meta]
- collection 1.17.1
- convert 3.1.1 [typed_data]
- coverage 1.6.3 [args logging package_config path source_maps stack_trace vm_service]
- crypto 3.0.3 [typed_data]
- dart_style 2.3.1 [analyzer args path pub_semver source_span]
- fake_async 1.3.1 [clock collection]
- file 6.1.4 [meta path]
- firebase_analytics_platform_interface 3.6.3 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.4+3 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.6.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 4.5.3 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.5.3 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_remote_config_platform_interface 1.4.3 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_web 1.4.3 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js]
- fixnum 1.1.0
- flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver async boolean_selector characters clock collection js matcher material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- freezed_annotation 2.2.0 [collection json_annotation meta]
- frontend_server_client 3.2.0 [async path]
- fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform]
- glob 2.1.2 [async collection file path string_scanner]
- graphs 2.3.1 [collection]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- intl 0.18.0 [clock meta path]
- io 1.0.4 [meta path string_scanner]
- js 0.6.7 [meta]
- json_annotation 4.8.0 [meta]
- lints 2.1.1
- matcher 0.12.15 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.2.0
- meta 1.9.1
- mime 1.0.4
- node_preamble 2.0.2
- package_config 2.1.0 [path]
- path 1.8.3
- platform 3.1.0
- plugin_platform_interface 2.1.4 [meta]
- pool 1.5.1 [async stack_trace]
- process 4.2.4 [file path platform]
- pub_semver 2.1.4 [collection meta]
- pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml]
- shelf 1.4.1 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 3.0.2 [path shelf shelf_static]
- shelf_static 1.1.2 [convert http_parser mime path shelf]
- shelf_web_socket 1.0.4 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_gen 1.3.2 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.3 [analyzer collection source_gen]
- source_map_stack_trace 2.1.1 [path source_maps stack_trace]
- source_maps 0.10.12 [source_span]
- source_span 1.9.1 [collection path term_glyph]
- stack_trace 1.11.0 [path]
- stream_channel 2.1.1 [async]
- stream_transform 2.1.0
- string_scanner 1.2.0 [source_span]
- sync_http 0.3.1
- term_glyph 1.2.1
- test 1.24.1 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core matcher]
- test_api 0.5.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- test_core 0.5.1 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api]
- timing 1.0.1 [json_annotation]
- typed_data 1.3.2 [collection]
- uuid 3.0.7 [crypto]
- vector_math 2.1.4
- vm_service 11.3.0
- watcher 1.1.0 [async path]
- web_socket_channel 2.2.0 [async crypto stream_channel]
- webdriver 3.0.2 [matcher path stack_trace sync_http]
- webkit_inspection_protocol 1.2.0 [logging]
- yaml 3.1.2 [collection source_span string_scanner]
➜  app git:(bug/firebase_messaging_blocks_thread) ✗ 

flutter doctor -v

[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F770820d darwin-arm64, locale en-US)
    • Flutter version 3.10.5 on channel stable at /Users/ixtlan/dev/bin/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (5 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/ixtlan/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.0

[✓] Android Studio (version 2022.2)
    • 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.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.80.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 (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64 • Android 13 (API 33) (emulator)
    • iPhone 14 Plus (mobile)     • 8FEF4CE4-9FDC-417A-A082-D12B9F330123 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64  • macOS 13.4.1 22F770820d darwin-arm64
    ! Device 1A251FDF600101 is not authorized.
      You might need to check your device for an authorization dialog.

[✓] Network resources
    • All expected network resources are available.

• No issues found!
kayumarie commented 1 year ago

Lil sample

https://github.com/firebase/flutterfire/assets/112617953/7083ffa6-6f7d-4b8b-845f-052ae4809648

danagbemava-nc commented 1 year ago

Hi @kayumarie, this is an issue with the underlying android SDK. See https://github.com/firebase/flutterfire/issues/7324#issuecomment-1184302457

Closing from here as this would have to be reported on the repo for the native android SDK.

Thank you

kayumarie commented 1 year ago

iOS SDK as well then, issue is reproducible on both platforms