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

🐛 [cloud_firestore] android.database.CursorWindowAllocationException #6823

Closed Tom3652 closed 3 years ago

Tom3652 commented 3 years ago

Bug report

Describe the bug

The issue made my app crash and i have seen it from crashlytics. It seems to be linked to the caching system of Firestore.

The error is : Could not allocate CursorWindow '/data/user/0/com.myappname/databases/firestore.%5BDEFAULT%5D.myappname-d.%28default%29' of size 2097152 due to error -13.

This issue may be related to #6821 but absolutely not sure ...

Steps to reproduce

It happened only once on Android and i have no idea how this happened or how to reproduce it yet unfortunately. However, i have set the cache size to 200MB :

int cacheSize = 200 * 1024 * 1024;
FirebaseFirestore.instance.settings = Settings(persistenceEnabled: true, cacheSizeBytes: cacheSize);

Because the error is about the size and seems to be with the SQLite DB.

Expected behavior

The application should not crash.

Additional context

Here is the main StackTrace from crashlytics :

Caused by android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/com.myappname/databases/firestore.%5BDEFAULT%5D.myappname-d.%28default%29' of size 2097152 due to error -13.
       at android.database.CursorWindow.nativeCreate(CursorWindow.java)
       at android.database.CursorWindow.<init>(CursorWindow.java:139)
       at android.database.CursorWindow.<init>(CursorWindow.java:120)
       at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:202)
       at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:147)
       at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:140)
       at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:232)
       at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:271)
       at com.google.firebase.firestore.local.SQLitePersistence$Query.first(SQLitePersistence.java:488)
       at com.google.firebase.firestore.local.SQLiteTargetCache.start(SQLiteTargetCache.java:54)
       at com.google.firebase.firestore.local.SQLitePersistence.start(SQLitePersistence.java:147)
       at com.google.firebase.firestore.core.ComponentProvider.initialize(ComponentProvider.java:132)
       at com.google.firebase.firestore.core.FirestoreClient.initialize(FirestoreClient.java:255)
       at com.google.firebase.firestore.core.FirestoreClient.lambda$new$0$FirestoreClient(FirestoreClient.java:103)
       at com.google.firebase.firestore.core.-$$Lambda$FirestoreClient$Eq-cAcb1C1mM4tyiJsLJXZ13tyU.run(:8)
       at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(AsyncQueue.java:436)
       at com.google.firebase.firestore.util.-$$Lambda$AsyncQueue$Y9GO7zO2DX6MzQJ5TbKtKW_NzO0.call(:2)
       at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(AsyncQueue.java:322)
       at com.google.firebase.firestore.util.-$$Lambda$AsyncQueue$SynchronizedShutdownAwareExecutor$pKSAgg-ozJ8RbUveSl-44aUfFQw.run(:4)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:229)
       at java.lang.Thread.run(Thread.java:919)

And before :

Fatal Exception: java.lang.RuntimeException: Internal error in Cloud Firestore (23.0.1).
       at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(AsyncQueue.java:534)
       at com.google.firebase.firestore.util.-$$Lambda$AsyncQueue$jx84dqgUsF4ojecSMurRqFLFD1Y.run(:2)
       at android.os.Handler.handleCallback(Handler.java:899)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:238)
       at android.app.ActivityThread.main(ActivityThread.java:7864)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:512)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:998)

then :

Caused by java.lang.RuntimeException: android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/com.myappname/databases/firestore.%5BDEFAULT%5D.myappname-d.%28default%29' of size 2097152 due to error -13.
       at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(AsyncQueue.java:325)
       at com.google.firebase.firestore.util.-$$Lambda$AsyncQueue$SynchronizedShutdownAwareExecutor$pKSAgg-ozJ8RbUveSl-44aUfFQw.run(:4)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:229)
       at java.lang.Thread.run(Thread.java:919)

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.2 20G95 darwin-x64, locale fr-FR) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] Connected device (3 available) • No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.13.4 Flutter SDK 2.2.3 myappname 1.0.0+1 dependencies: - app_tracking_transparency 2.0.1 [flutter] - badges 2.0.1 [flutter] - better_player 0.0.72 [flutter cupertino_icons wakelock pedantic meta flutter_widget_from_html_core visibility_detector path_provider collection xml] - cached_network_image 3.1.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - camera 0.8.1+7 [camera_platform_interface flutter pedantic quiver] - circular_menu 1.2.3 [flutter] - clipboard 0.1.3 [flutter] - cloud_firestore 2.4.0 [cloud_firestore_platform_interface cloud_firestore_web firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 3.0.0 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - connectivity 3.0.6 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - country_code_picker 2.0.2 [flutter modal_bottom_sheet collection universal_platform] - crypto 3.0.1 [collection typed_data] - cupertino_back_gesture 0.1.0 [flutter] - cupertino_icons 1.0.3 - extended_image 4.1.0 [extended_image_library flutter meta] - extended_tabs 2.3.0 [flutter] - firebase_analytics 8.2.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta] - firebase_auth 3.0.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.4.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.1.1 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_database 7.1.2 [firebase_core flutter] - firebase_dynamic_links 2.0.7 [firebase_core flutter] - firebase_in_app_messaging 0.5.0+7 [firebase_core flutter meta] - firebase_messaging 10.0.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_performance 0.7.0+7 [firebase_core flutter] - firebase_storage 10.0.1 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_app_badger 1.2.0 [flutter] - flutter_arc_text 0.5.0 [characters flutter] - flutter_cache_manager 3.1.2 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_contacts 1.1.0+3 [flutter] - flutter_facebook_auth 3.5.0 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web] - flutter_ffmpeg 0.4.2 [flutter] - flutter_image_compress 1.1.0 [flutter] - flutter_local_notifications 8.1.1+1 [flutter flutter_local_notifications_platform_interface platform timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection meta path typed_data vector_math] - flutter_sound_lite 8.3.9 [path_provider recase uuid provider flutter_spinkit path synchronized logger flutter flutter_sound_platform_interface flutter_sound_web] - flutter_staggered_grid_view 0.4.0 [flutter] - flutter_svg 0.22.0 [flutter meta path_drawing vector_math xml] - fluttertoast 8.0.8 [flutter flutter_web_plugins] - geocoding 2.0.0 [flutter geocoding_platform_interface] - geolocator 7.4.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web] - google_maps_flutter 2.0.6 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface] - google_mobile_ads 0.13.3 [meta flutter] - google_sign_in 5.0.7 [flutter google_sign_in_platform_interface google_sign_in_web meta] - image_editor 1.0.0 [flutter] - in_app_review 2.0.2 [flutter in_app_review_platform_interface] - intl 0.17.0 [clock path] - light_compressor 1.1.1 [flutter] - modal_bottom_sheet 2.0.0 [flutter] - path 1.8.0 - path_provider 2.0.2 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - permission_handler 8.1.4+2 [flutter meta permission_handler_platform_interface] - photo_manager 1.3.1 [flutter] - progressive_image 2.0.0 [flutter] - provider 5.0.0 [collection flutter nested] - pull_to_refresh 2.0.0 [flutter] - rive 0.7.28 [collection flutter graphs http meta] - scroll_to_index 2.0.0 [flutter] - scrollable_positioned_list 0.2.0-nullsafety.0 [flutter collection] - share_plus 2.1.4 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web] - shared_preferences 2.0.6 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows] - sign_in_with_apple 3.0.0 [flutter meta] - sliver_tools 0.2.5 [flutter] - translator 0.1.7 [http] - url_launcher 6.0.9 [flutter meta url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - uuid 3.0.4 [crypto] - video_player 2.1.13 [flutter flutter_test meta video_player_platform_interface video_player_web] - visibility_detector 0.2.0 [flutter] - volume_watcher 2.0.1 [flutter] - webview_flutter 2.0.12 [flutter] dev dependencies: - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - async 2.6.1 [meta collection] - boolean_selector 2.1.0 [source_span string_scanner] - cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface] - camera_platform_interface 2.1.0 [cross_file flutter meta plugin_platform_interface stream_transform] - characters 1.1.0 - charcode 1.2.0 - clock 1.1.0 - cloud_firestore_platform_interface 5.3.0 [collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 2.3.0 [cloud_firestore_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.0.8 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.0.10 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.15.0 - connectivity_for_web 0.4.0 [connectivity_platform_interface flutter_web_plugins flutter] - connectivity_macos 0.2.0 [flutter] - connectivity_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - cross_file 0.3.1+4 [flutter meta] - csslib 0.17.0 [source_span] - extended_image_library 3.1.0 [crypto flutter http_client_helper path path_provider] - fake_async 1.2.0 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase 9.0.1 [http http_parser js] - firebase_analytics_platform_interface 2.0.1 [flutter meta] - firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta] - firebase_auth_platform_interface 6.0.0 [firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 3.0.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.0.1 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.1.0 [collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 3.0.3 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.0.3 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 4.0.0 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.0.0 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_blurhash 0.6.0 [flutter meta pedantic] - flutter_facebook_auth_platform_interface 2.7.0 [flutter plugin_platform_interface] - flutter_facebook_auth_web 2.6.0+2 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface] - flutter_local_notifications_platform_interface 4.0.1 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.2 [flutter] - flutter_sound_platform_interface 8.3.9 [flutter meta plugin_platform_interface logger] - flutter_sound_web 8.3.9 [flutter_sound_platform_interface flutter logger flutter_web_plugins meta js] - flutter_spinkit 5.0.0 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - flutter_widget_from_html_core 0.6.2 [csslib flutter html] - geocoding_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - geolocator_android 1.0.0 [flutter geolocator_platform_interface] - geolocator_apple 1.0.0 [flutter geolocator_platform_interface] - geolocator_platform_interface 2.3.2 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.0.6 [flutter flutter_web_plugins geolocator_platform_interface] - google_maps_flutter_platform_interface 2.1.1 [collection flutter meta plugin_platform_interface stream_transform] - google_sign_in_platform_interface 2.0.1 [flutter meta quiver] - google_sign_in_web 0.10.0+1 [flutter flutter_web_plugins google_sign_in_platform_interface js meta] - graphs 2.0.0 - html 0.15.0 [csslib source_span] - http 0.13.3 [async http_parser meta path pedantic] - http_client_helper 2.0.2 [http] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - in_app_review_platform_interface 2.0.2 [flutter url_launcher plugin_platform_interface platform] - js 0.6.3 - logger 1.0.0 - matcher 0.12.10 [stack_trace] - meta 1.3.0 - mime 1.0.0 - nested 1.0.0 [flutter] - octo_image 1.0.0+1 [flutter flutter_blurhash] - path_drawing 0.5.1 [vector_math meta path_parsing flutter] - path_parsing 0.2.1 [vector_math meta] - path_provider_linux 2.0.2 [flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.2 [flutter] - path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.3 [ffi flutter meta path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_platform_interface 3.6.1 [flutter meta plugin_platform_interface] - petitparser 4.1.0 [meta] - platform 3.0.0 - plugin_platform_interface 2.0.1 [meta] - process 4.2.3 [file path platform] - quiver 3.0.1 [matcher] - recase 4.0.0 - rxdart 0.27.1 - share_plus_linux 2.0.3 [share_plus_platform_interface file flutter meta url_launcher] - share_plus_macos 2.0.2 [share_plus_platform_interface flutter] - share_plus_platform_interface 2.0.1 [flutter meta mime plugin_platform_interface] - share_plus_web 2.0.4 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta] - share_plus_windows 2.0.3 [share_plus_platform_interface flutter meta url_launcher] - shared_preferences_linux 2.0.2 [file meta flutter path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 2.0.2 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.1 [flutter flutter_web_plugins meta shared_preferences_platform_interface] - shared_preferences_windows 2.0.2 [flutter file meta path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sky_engine 0.0.99 - source_span 1.8.1 [collection path term_glyph] - sqflite 2.0.0+3 [flutter sqflite_common path] - sqflite_common 2.0.0+2 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.3.0 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.7.0 [path] - typed_data 1.3.0 [collection] - universal_platform 1.0.0+1 - url_launcher_linux 2.0.1 [flutter] - url_launcher_macos 2.0.1 [flutter] - url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface] - url_launcher_web 2.0.2 [flutter flutter_web_plugins meta url_launcher_platform_interface] - url_launcher_windows 2.0.1 [flutter] - vector_math 2.1.0 - video_player_platform_interface 4.1.0 [flutter meta flutter_test] - video_player_web 2.0.2 [flutter flutter_web_plugins meta video_player_platform_interface] - wakelock 0.5.3+3 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows] - wakelock_macos 0.1.0+2 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.2.1+2 [flutter meta] - wakelock_web 0.2.0+2 [flutter flutter_web_plugins js wakelock_platform_interface] - wakelock_windows 0.1.0+1 [flutter wakelock_platform_interface win32] - win32 2.2.5 [ffi] - xdg_directories 0.2.0 [meta path process] - xml 5.1.2 [collection meta petitparser] ```

Tom3652 commented 3 years ago

I am adding a comment as i have found this question.

I have never heard about this or how this can happen but it doesn't seem related to #6821 as it is a limit on Android only.

russellwheatley commented 3 years ago

It does indeed look like the limit was reached in this particular instance. error code 13 indicates that the device's disk (primary or temp) was full. I'm going to close as this isn't actionable for Flutterfire.

Tom3652 commented 3 years ago

My Android phone where the crash occurred has 37Go of free disk space... Besides, can't Firestore catch the error instead of letting the app crash ? Or do you mean it's a Firestore SDK issue (that i should address to the support or somewhere else) not a Flutterfire one ?

I will make more tests to fill the free storage and see if this still happens

russellwheatley commented 3 years ago

The primary disk space is 37gb, but as the link suggests, the temporary disk partition could be much smaller.

If there is a problem with the way Firestore handles it internally, it will in all likelihood be a firebase-android-sdk issue. However, I will reopen if this is something actionable here that you can reproduce.