flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_app_check] App Check adds 2s delay to the first Firestore Read

Open prologikus opened this issue 1 year ago • 2 comments

Bug report

When integrating Firebase App Check with Firestore in a Flutter project, there is a noticeable delay of approximately 2 seconds during the first attempt to read any document from Firestore. This issue has been consistently reproducible and impacts the initial load performance of Firestore data fetching operations in the presence of Firebase App Check.

Steps to reproduce

  1. Create a new Flutter project.
  2. Integrate the following Firebase-related dependencies into the project: firebase_auth, firebase_core, cloud_firestore, and firebase_app_check.
  3. Properly set up and configure the Firebase project with the necessary services enabled.
  4. Implement a function to read a document from Firestore and call this function as early as possible in the application's lifecycle.

Expected Behavior

The read operation from Firestore should complete with minimal delay, ensuring a smooth and responsive user experience, even with Firebase App Check enabled for added security.

Sample project

A sample project demonstrating this issue is available at: https://github.com/prologikus/appcheckdelayyy

Flutter doctor

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.22631.3007], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.7.5)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.86.0)
[√] Connected device (4 available)
[√] Network resources

Flutter dependencies

Click To Expand
Dart SDK 3.2.6
Flutter SDK 3.16.9
testtt 1.0.0+1

dependencies:
- cloud_firestore 4.15.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]   
- cupertino_icons 1.0.6
- firebase_app_check 0.2.1+9 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 4.17.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 2.25.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- 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.17 [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
- cloud_firestore_platform_interface 6.1.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 3.10.0 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.18.0
- fake_async 1.3.1 [clock collection]
- firebase_app_check_platform_interface 0.1.0+11 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.1.0+11 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 7.1.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.9.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta web]
- firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.11.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta web]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- 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]
- typed_data 1.3.2 [collection]
- vector_math 2.1.4
- web 0.3.0

prologikus avatar Feb 02 '24 11:02 prologikus

Thanks for the report @prologikus It seems like a native issue rather than of the plugin, because flutterfire plugins are thin wrappers around native firebase SDKS and shares data through dart. See this for reference. If you are able to replicate it without Flutter, just using native Android, then you may need to report this in dedicated repo.

darshankawar avatar Feb 05 '24 13:02 darshankawar

Hey @prologikus. 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 avatar Feb 14 '24 02:02 google-oss-bot

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

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

google-oss-bot avatar Feb 23 '24 02:02 google-oss-bot