Skip to content

[firebase_messaging]: ANR on second notification with no main thread blockage #17274

Open
@chrislciaba

Description

@chrislciaba

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

Android

Description

I'm receiving an ANR after receiving the first notification with my FirebaseMessaging configuration. There is no issue with notifications on iOS just android and I've confirmed my handlers are finishing, don't see anything blocking the main thread in my traces, but there does appear to be some lock contention potentially. The only useful error log on the flutter side is:

I/g.yada ( 6504): Thread[2,tid=6510,WaitingInMainSignalCatcherLoop,Thread*=0xb400745e0ea3af50,peer=0x14001500,"Signal Catcher"]: reacting to signal 3

Here is my current setup:

versions

  firebase_messaging: ^15.1.3
  firebase_core: ^3.6.0

main

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  
  FirebaseMessaging messaging = FirebaseMessaging.instance;
  NotificationSettings settings = await messaging.requestPermission(
    alert: true,
    announcement: false,
    badge: true,
    carPlay: false,
    criticalAlert: false,
    provisional: false,
    sound: true,
  );
  

  await FcmManager.initialize();

FCM manager

static Future<void> initialize() async {
    NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    safePrint('User granted permission: ${settings.authorizationStatus}');

    FirebaseMessaging.onBackgroundMessage(_handleMessage);

    // Get any messages which caused the application to open from
    // a terminated state.
    RemoteMessage? initialMessage =
        await FirebaseMessaging.instance.getInitialMessage();

    // If the message also contains a data property with a "type" of "chat",
    // navigate to a chat screen
    if (initialMessage != null) {
      await _handleMessage(initialMessage);
    }

    // Also handle any interaction when the app is in the background via a
    // Stream listener
    FirebaseMessaging.onMessageOpenedApp.listen(_handleMessage);

    // Handle messages when the app is in the foreground
    FirebaseMessaging.onMessage.listen(_handleForegroundMessage);
    
    FirebaseMessaging.instance.onTokenRefresh
      .listen((fcmToken) async {
        await _registerPushToken(fcmToken);
      })
      .onError((err) {
        // Error getting token.
      });
  }

Reproducing the issue

  • Send 1 push notification. It goes through fine and uses the foreground handler
  • Send a second one. Nothing happens for about 40 seconds and then (1) an ANR occurs (2) the background message handler fires instead of the foreground handler

Firebase Core version

3.13.0

Flutter Version

3.24.4

Relevant Log Output

Flutter dependencies

Expand Flutter dependencies snippet
Dart SDK 3.5.4
Flutter SDK 3.27.4 
yada 1.0.0+2

dependencies:
- amplify_api 2.2.0 [amplify_api_dart amplify_core amplify_flutter connectivity_plus flutter meta plugin_platform_interface]
- amplify_auth_cognito 2.2.0 [amplify_analytics_pinpoint amplify_analytics_pinpoint_dart amplify_auth_cognito_dart amplify_core amplify_flutter amplify_secure_storage async flutter meta path plugin_platform_interface]
- amplify_authenticator 2.1.0 [amplify_auth_cognito amplify_core amplify_flutter async aws_common collection flutter flutter_localizations intl meta package_info_plus qr_flutter smithy stream_transform url_launcher]
- amplify_flutter 2.2.0 [amplify_core amplify_secure_storage aws_common collection flutter meta]
- auto_size_text 3.0.0 [flutter]
- awesome_notifications 0.9.3+1 [flutter flutter_web_plugins plugin_platform_interface intl]
- awesome_notifications_core 0.9.3 [flutter flutter_web_plugins plugin_platform_interface]
- build_runner 2.4.13 [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]
- cached_network_image 3.3.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image]
- collection 1.18.0
- cupertino_icons 1.0.8
- dropdown_button2 2.3.9 [flutter meta]
- firebase_core 3.13.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 15.2.5 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_animate 4.5.0 [flutter flutter_shaders]
- flutter_app_badge 2.0.2 [flutter]
- flutter_app_badge_control 0.0.2 [flutter plugin_platform_interface]
- flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid]
- flutter_google_places 0.4.0 [flutter google_api_headers google_maps_webservice http rxdart]
- flutter_image_compress 2.4.0 [flutter flutter_image_compress_platform_interface flutter_image_compress_common flutter_image_compress_web flutter_image_compress_macos flutter_image_compress_ohos]
- flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml]
- flutter_local_notifications 17.2.4 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_slidable 3.1.2 [flutter]
- fluttertoast 8.2.12 [flutter flutter_web_plugins web]
- font_awesome_flutter 10.6.0 [flutter]
- format 1.5.2 [characters intl]
- from_css_color 2.0.0 [flutter]
- get 4.7.2 [flutter web]
- go_router 12.1.3 [collection flutter flutter_web_plugins logging meta]
- google_fonts 6.1.0 [flutter http path_provider crypto]
- google_maps_flutter 2.10.0 [flutter google_maps_flutter_android google_maps_flutter_ios google_maps_flutter_platform_interface google_maps_flutter_web]
- google_maps_place_picker_mb 3.1.2 [flutter geolocator google_api_headers google_maps_flutter flutter_google_maps_webservices http provider tuple uuid package_info_plus]
- http 1.3.0 [async http_parser meta web]
- image_picker 1.1.2 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows]
- intl 0.19.0 [clock meta path]
- json_annotation 4.8.1 [meta]
- json_path 0.7.2 [iregexp maybe_just_nothing petitparser rfc_6901]
- json_serializable 6.7.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
- loader_overlay 4.0.4+1 [flutter back_button_interceptor]
- logging 1.3.0
- package_info_plus 8.0.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock]
- package_info_plus_platform_interface 3.0.0 [flutter meta plugin_platform_interface]
- page_transition 2.1.0 [flutter]
- path_provider 2.1.3 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- path_provider_android 2.2.5 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.0 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- provider 6.1.2 [collection flutter nested]
- push 2.3.0 [flutter push_platform_interface push_android push_ios push_macos]
- sentry_flutter 8.13.0 [flutter flutter_web_plugins sentry package_info_plus meta ffi file collection]
- shared_preferences 2.2.3 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shared_preferences_android 2.2.1 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.3.5 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.3.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.2.1 [flutter flutter_web_plugins shared_preferences_platform_interface]
- sqflite 2.2.6 [flutter sqflite_common path]
- timeago 3.6.1 [intl]
- url_launcher 6.3.1 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- url_launcher_android 6.3.10 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.3.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface]
- web 1.1.0
- web_socket_channel 2.4.0 [async crypto stream_channel]

dev dependencies:
- flutter_lints 4.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]
- lints 4.0.0

dependency overrides:
- package_info_plus 8.0.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock]
- package_info_plus_platform_interface 3.0.0 [flutter meta plugin_platform_interface]
- uuid 4.5.1 [crypto sprintf meta fixnum]

transitive dependencies:
- _fe_analyzer_shared 72.0.0 [meta]
- _flutterfire_internals 1.3.54 [collection firebase_core firebase_core_platform_interface flutter meta]
- _macros 0.3.2
- amplify_analytics_pinpoint 2.2.0 [amplify_analytics_pinpoint_dart amplify_core amplify_db_common amplify_secure_storage aws_common device_info_plus flutter meta package_info_plus path_provider]
- amplify_analytics_pinpoint_dart 0.4.2 [amplify_core amplify_db_common_dart amplify_secure_storage_dart aws_common aws_signature_v4 built_collection built_value collection drift intl meta path smithy smithy_aws uuid]
- amplify_api_dart 0.5.2 [amplify_core async aws_common collection json_annotation meta plugin_platform_interface stream_transform web_socket_channel]
- amplify_auth_cognito_dart 0.11.2 [amplify_analytics_pinpoint_dart amplify_core amplify_secure_storage_dart async aws_common aws_signature_v4 built_collection built_value clock collection convert crypto ffi fixnum http intl js json_annotation meta oauth2 path smithy smithy_aws stream_transform uuid win32 win32_registry worker_bee]
- amplify_core 2.2.0 [async aws_common aws_signature_v4 collection graphs intl json_annotation logging meta retry stack_trace uuid]
- amplify_db_common 0.4.2 [amplify_db_common_dart drift flutter path path_provider]
- amplify_db_common_dart 0.4.3 [amplify_core async aws_common drift meta path sqlite3]
- amplify_secure_storage 0.5.4 [amplify_secure_storage_dart async file flutter meta path path_provider path_provider_windows]
- amplify_secure_storage_dart 0.5.1 [async aws_common built_collection built_value ffi file js meta path win32 worker_bee]
- analyzer 6.7.0 [_fe_analyzer_shared collection convert crypto glob macros meta package_config path pub_semver source_span watcher yaml]
- archive 4.0.2 [crypto path posix]
- args 2.6.0
- async 2.11.0 [collection meta]
- aws_common 0.7.1 [async built_collection built_value collection http2 js json_annotation logging meta mime os_detect path stream_transform uuid]
- aws_signature_v4 0.6.1 [async aws_common collection convert crypto json_annotation meta path]
- back_button_interceptor 8.0.4 [collection flutter]
- boolean_selector 2.1.1 [source_span string_scanner]
- build 2.4.1 [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.2 [built_collection built_value crypto http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.4.2 [analyzer async build collection convert crypto graphs logging package_config path pool pub_semver stream_transform yaml]
- build_runner_core 7.3.2 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta package_config path pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.9.3 [built_collection collection fixnum meta]
- cached_network_image_platform_interface 4.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.2.0 [cached_network_image_platform_interface flutter flutter_cache_manager]
- characters 1.3.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- cli_util 0.4.2 [meta path]
- clock 1.1.1
- code_builder 4.10.1 [built_collection built_value collection matcher meta]
- connectivity_plus 6.1.3 [flutter flutter_web_plugins connectivity_plus_platform_interface web meta nm collection]
- connectivity_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- convert 3.1.2 [typed_data]
- crclib 3.0.0 [meta tuple]
- cross_file 0.3.4+2 [meta web]
- crypto 3.0.6 [typed_data]
- csslib 1.0.2 [source_span]
- dart_style 2.3.7 [analyzer args collection package_config path pub_semver source_span]
- dbus 0.7.11 [args ffi meta xml]
- device_info_plus 10.1.2 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta web win32 win32_registry]
- device_info_plus_platform_interface 7.0.2 [flutter meta plugin_platform_interface]
- drift 2.14.1 [async convert collection js meta stream_channel sqlite3 path]
- fake_async 1.3.1 [clock collection]
- ffi 2.1.3
- file 7.0.1 [meta path]
- file_selector_linux 0.9.3+2 [cross_file file_selector_platform_interface flutter]
- file_selector_macos 0.9.4+2 [cross_file file_selector_platform_interface flutter]
- file_selector_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface]
- file_selector_windows 0.9.3+4 [cross_file file_selector_platform_interface flutter]
- firebase_core_platform_interface 5.4.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.22.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_messaging_platform_interface 4.6.5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.10.5 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web]
- fixnum 1.1.1
- flutter_google_maps_webservices 1.1.1 [http meta json_annotation]
- flutter_image_compress_common 1.0.6 [flutter flutter_image_compress_platform_interface]
- flutter_image_compress_macos 1.0.3 [flutter flutter_image_compress_platform_interface]
- flutter_image_compress_ohos 0.0.3 [flutter flutter_image_compress_platform_interface]
- flutter_image_compress_platform_interface 1.0.5 [flutter plugin_platform_interface cross_file]
- flutter_image_compress_web 0.1.5 [flutter flutter_web_plugins flutter_image_compress_platform_interface web]
- flutter_local_notifications_linux 4.0.1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 7.2.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.24 [flutter]
- flutter_shaders 0.1.3 [flutter vector_math]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- frontend_server_client 4.0.0 [async path]
- geolocator 10.1.1 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- geolocator_android 4.6.1 [flutter geolocator_platform_interface meta uuid]
- geolocator_apple 2.3.9 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.2.4 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.2.1 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.2.3 [flutter geolocator_platform_interface]
- glob 2.1.3 [async collection file path string_scanner]
- google_api_headers 2.0.3 [flutter package_info_plus]
- google_maps 8.1.1 [meta web]
- google_maps_flutter_android 2.14.12 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_ios 2.13.2 [flutter google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_platform_interface 2.10.0 [collection flutter plugin_platform_interface stream_transform]
- google_maps_flutter_web 0.5.10 [collection flutter flutter_web_plugins google_maps google_maps_flutter_platform_interface sanitize_html stream_transform web]
- google_maps_webservice 0.0.20-nullsafety.5 [http meta json_annotation]
- graphs 2.3.2 [collection]
- html 0.15.5 [csslib source_span]
- http2 2.3.1
- http_multi_server 3.2.2 [async]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image 4.5.2 [archive meta xml]
- image_picker_android 0.8.12+20 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 3.0.6 [flutter flutter_web_plugins image_picker_platform_interface mime web]
- image_picker_ios 0.8.12+2 [flutter image_picker_platform_interface]
- image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_macos 0.2.1+2 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_platform_interface 2.10.1 [cross_file flutter http plugin_platform_interface]
- image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface]
- io 1.0.5 [meta path string_scanner]
- iregexp 0.1.2 [petitparser]
- js 0.6.7 [meta]
- leak_tracker 10.0.5 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.5 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- macros 0.1.2-main.4 [_macros]
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- maybe_just_nothing 0.5.3
- meta 1.15.0
- mime 1.0.6
- nested 1.0.0 [flutter]
- nm 0.5.0 [dbus]
- oauth2 2.0.3 [collection crypto http http_parser]
- octo_image 2.1.0 [flutter]
- os_detect 2.0.3 [meta web]
- package_config 2.1.1 [path]
- path 1.9.0
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- petitparser 6.0.2 [meta]
- platform 3.1.6
- plugin_platform_interface 2.1.8 [meta]
- pool 1.5.1 [async stack_trace]
- posix 6.0.1 [ffi meta path]
- pub_semver 2.1.5 [collection meta]
- pubspec_parse 1.4.0 [checked_yaml collection json_annotation pub_semver yaml]
- push_android 0.6.0 [flutter push_platform_interface]
- push_ios 0.5.1 [flutter push_platform_interface]
- push_macos 0.0.1 [flutter cupertino_icons]
- push_platform_interface 0.6.0 [flutter plugin_platform_interface]
- qr 3.0.2 [meta]
- qr_flutter 4.1.0 [flutter qr]
- retry 3.1.2
- rfc_6901 0.2.0
- rxdart 0.27.7
- sanitize_html 2.1.0 [html meta]
- sentry 8.13.0 [http meta stack_trace uuid collection]
- shared_preferences_linux 2.3.2 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_windows 2.3.2 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.1 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 2.0.1 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- smithy 0.7.1 [async aws_common built_collection built_value collection convert crypto fixnum http_parser intl json_annotation meta path retry shelf typed_data xml]
- smithy_aws 0.7.1 [aws_common aws_signature_v4 built_collection built_value collection convert crclib crypto intl json_annotation meta path smithy xml]
- source_gen 1.5.0 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.5 [analyzer collection source_gen]
- source_span 1.10.0 [collection path term_glyph]
- sprintf 7.0.0
- sqflite_common 2.5.4+6 [synchronized path meta]
- sqlite3 2.4.2 [collection ffi js meta path]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- stream_transform 2.1.1
- string_scanner 1.2.0 [source_span]
- synchronized 3.3.0+3
- term_glyph 1.2.1
- test_api 0.7.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- timezone 0.9.4 [path]
- timing 1.0.1 [json_annotation]
- tuple 2.0.2
- typed_data 1.4.0 [collection]
- url_launcher_linux 3.2.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.2.2 [flutter url_launcher_platform_interface]
- url_launcher_web 2.3.3 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.4 [flutter url_launcher_platform_interface]
- vector_math 2.1.4
- vm_service 14.2.5
- watcher 1.1.1 [async path]
- win32 5.10.1 [ffi]
- win32_registry 1.1.5 [ffi win32]
- worker_bee 0.3.1 [async aws_common built_collection built_value collection js meta path stack_trace stream_channel stream_transform]
- xdg_directories 1.1.0 [meta path]
- xml 6.5.0 [collection meta petitparser]
- yaml 3.1.3 [collection source_span string_scanner]

Additional context and comments

Image Image

Added two images from my traces for further info

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions