Is there an existing issue for this?
Which plugins are affected?
Storage
Which platforms are affected?
Android, iOS
Description
I have previously created #16753 but the OOM was on the dart side.
However, i have managed to reproduce in my real app a crash that i have got 2 days ago in my Crashlytics dashboard.
This is the native OOM stack trace that some of my live users are experiencing currently.
Of course they have the version using the putData instead of putFile but it's not a dart OOM...
-> What i believe is happening is that for example the app has 300MB RAM available for it to run. Let's say my app is consuming 250MB to run with everything inside / UI / Code etc...
That means there is a 50MB left free memory to use, but if i upload a 200MB file at this moment, it's like firebase_storage is reducing the 200MB by chunks to perform the upload, but the initial chunk is anyway > 50MB which cause the crash.
For example in #13460 and #13385 it is probably fixed that firebase_storage itself handles perfectly the large files now, but i am not sure it takes in consideration the total available free memory before starting the upload, otherwise i would not have the above stack trace.
Note : I have noticed it on Android because my phone has a low RAM available compared to my iPhone, but the same behavior may exist on iOS as well simply at a higher degree, but it is easier to reproduce it on Android than iOS.
Reproducing the issue
I have not managed yet to produce a sample code, but here are the steps :
- Have an app that runs with a relatively high memory usage around (200MB) (by displaying few very large images / videos for example)
- Try to upload a very large file
- See the crash
I am working on the reproductible example, i save the issue to not lose it but i will update with the reproductible sample code.
Firebase Core version
3.8.0
Flutter Version
3.24.5
Relevant Log Output
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 255746824 byte allocation with 25165824 free bytes and 127MB until OOM, target footprint 160196792, growth limit 268435456
at io.flutter.plugin.common.StandardMessageCodec.readBytes(StandardMessageCodec.java:320)
at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:386)
at io.flutter.plugins.firebase.storage.GeneratedAndroidFirebaseStorage$FirebaseStorageHostApiCodec.readValueOfType(GeneratedAndroidFirebaseStorage.java:692)
at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:424)
at io.flutter.plugins.firebase.storage.GeneratedAndroidFirebaseStorage$FirebaseStorageHostApiCodec.readValueOfType(GeneratedAndroidFirebaseStorage.java:692)
at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
at io.flutter.plugin.common.StandardMessageCodec.decodeMessage(StandardMessageCodec.java:89)
at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:319)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:224)
at android.os.Looper.loop(Looper.java:318)
at android.app.ActivityThread.main(ActivityThread.java:8780)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Flutter dependencies
Expand Flutter dependencies snippet
Dart SDK 3.5.4
Flutter SDK 3.24.5
test_database 1.0.0+1
dependencies:
- firebase_core 3.8.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_storage 12.3.6 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- 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]
- video_player 2.9.2 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]
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]
transitive dependencies:
- _flutterfire_internals 1.3.46 [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
- cross_file 0.3.4+2 [meta web]
- csslib 1.0.2 [source_span]
- fake_async 1.3.1 [clock collection]
- 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+3 [cross_file file_selector_platform_interface flutter]
- firebase_core_platform_interface 5.3.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.18.1 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_storage_platform_interface 5.1.33 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.10.5 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http meta web]
- flutter_plugin_android_lifecycle 2.0.23 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- html 0.15.5 [csslib source_span]
- http 1.2.2 [async http_parser meta web]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.12+18 [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+1 [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+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_platform_interface 2.10.0 [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]
- 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]
- lints 4.0.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.15.0
- mime 2.0.0
- path 1.9.0
- 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.7.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- typed_data 1.4.0 [collection]
- vector_math 2.1.4
- video_player_android 2.7.16 [flutter video_player_platform_interface]
- video_player_avfoundation 2.6.3 [flutter video_player_platform_interface]
- video_player_platform_interface 6.2.3 [flutter plugin_platform_interface]
- video_player_web 2.3.3 [flutter flutter_web_plugins video_player_platform_interface web]
- vm_service 14.2.5
- web 1.1.0
Additional context and comments
No response
Is there an existing issue for this?
Which plugins are affected?
Storage
Which platforms are affected?
Android, iOS
Description
I have previously created #16753 but the OOM was on the dart side.
However, i have managed to reproduce in my real app a crash that i have got 2 days ago in my Crashlytics dashboard.
This is the native OOM stack trace that some of my live users are experiencing currently.
Of course they have the version using the
putDatainstead ofputFilebut it's not a dart OOM...-> What i believe is happening is that for example the app has 300MB RAM available for it to run. Let's say my app is consuming 250MB to run with everything inside / UI / Code etc...
That means there is a 50MB left free memory to use, but if i upload a 200MB file at this moment, it's like
firebase_storageis reducing the 200MB by chunks to perform the upload, but the initial chunk is anyway > 50MB which cause the crash.For example in #13460 and #13385 it is probably fixed that
firebase_storageitself handles perfectly the large files now, but i am not sure it takes in consideration the total available free memory before starting the upload, otherwise i would not have the above stack trace.Note : I have noticed it on Android because my phone has a low RAM available compared to my iPhone, but the same behavior may exist on iOS as well simply at a higher degree, but it is easier to reproduce it on Android than iOS.
Reproducing the issue
I have not managed yet to produce a sample code, but here are the steps :
I am working on the reproductible example, i save the issue to not lose it but i will update with the reproductible sample code.
Firebase Core version
3.8.0
Flutter Version
3.24.5
Relevant Log Output
Flutter dependencies
Expand
Flutter dependenciessnippetAdditional context and comments
No response