[firebase_storage]: Windows: getData() crashes with access violation (use-after-free of StorageReference in ReferenceGetData)
Maintainers usually reply within 4 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- desktop-dev
Research direction
Start in the firebase_storage Windows plugin source, at the pigeon handler ReferenceGetData shown in the issue snippet: it builds a local StorageReference via GetCPPStorageReferenceFromPigeon, calls GetBytes, sleeps 1ms, then returns while the SDK retry thread still dereferences the reference. Read the surrounding Reference* handlers (putData, putFile, writeToFile, getDownloadURL) for the same lifetime pattern. Done means the reference outlives the future (e.g. held in a std::shared_ptr captured by the OnCompletion callback), the ::Sleep(1) is gone, and repeated Windows downloads no longer crash.
Written by the indexing model from the issue text.
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Storage
Which platforms are affected?
Windows
Description
n Windows, Reference.getData() intermittently crashes the whole app with an access violation
(0xc0000005). There is no Dart exception; flutter run just prints "Lost connection to device." It
happens reliably when downloading many small blobs in a row (in our app: syncing ~200 results, one
getData() per result). Some downloads succeed first, then one crashes. The crash offset is identical
across runs.
Expected: getData() returns the bytes or throws a FirebaseException.
Actual: native crash in the Firebase C++ SDK Storage worker thread.
Symbolized stack of the crashing thread (from a Windows Error Reporting full dump of a Debug build,
symbolized with the PDB):
firebase::Mutex::Acquire
firebase::MutexLock::MutexLock
firebase::FutureManager::GetFutureApi
firebase::storage::internal::StorageReferenceInternal::future
firebase::storage::internal::StorageReferenceInternal::AsyncSendRequestWithRetry<unsigned __int64>
std::invoke<... StorageReferenceInternal::* ...>
std::thread::_Invoke<... StorageReferenceInternal ...>
So the retry/worker thread started by GetBytes calls StorageReferenceInternal::future() after the
reference has been destroyed.
(unchanged between 12.4.10 and 13.6.1):
StorageReference cpp_reference =
GetCPPStorageReferenceFromPigeon(app, reference);
auto byte_buffer = std::make_shared<std::vector<uint8_t>>(max_size);
Future<size_t> future_result =
cpp_reference.GetBytes(byte_buffer->data(), max_size);
::Sleep(1); // timing for c++ sdk grabbing a mutex
future_result.OnCompletion(...);
} // cpp_reference is destroyed here while GetBytes is still running
cpp_reference is a local, so it is destroyed when the method returns, while
AsyncSendRequestWithRetry is still running on its own thread and later dereferences the reference's
internal state. The ::Sleep(1) only masks the race; on slower machines or with many downloads in a row
it eventually loses.
A possible fix is to keep the StorageReference alive until the future completes. For example, move it
into a std::shared_ptr captured by the OnCompletion lambda, or keep it in a map until completion.
Then remove the Sleep(1). Other Reference* methods that start async operations on a local
StorageReference (e.g. putData, putFile, writeToFile, getDownloadURL) may have the same issue.
iOS and macOS are not affected (they use the native Apple SDK).
Reproducing the issue
Reproducing the issue:
- Windows 10/11,
flutter run -d windows(Debug). - Upload ~100–200 small files (a few KB to a few hundred KB each) to Storage.
- Download them sequentially:
for (final ref in refs) {
final data = await ref.getData(); // crashes after some iterations
}
- The app terminates with "Lost connection to device". Event Viewer shows
0xc0000005in the app's exe
(the C++ SDK is statically linked), always at the same offset.
It is timing-dependent; on our (older) Windows laptop it crashes within the first ~15 downloads every
time.
Firebase Core version: 3.15.2
Flutter Version: 3.41.6
Relevant Log Output:
Faulting application: kinesense_app.exe
Faulting module: kinesense_app.exe
Exception code: 0xc0000005
Fault offset: 0x000000000188a614 (resolves to firebase::Mutex::Acquire)
Flutter dependencies: paste the output of flutter pub deps -- --style=compact from Windows here, or at
least the firebase_* lines: firebase_core 3.15.2, firebase_storage 12.4.10,
firebase_storage_platform_interface 5.2.10, Firebase C++ SDK 12.7.0 (from firebase_core's Windows
CMake).
Additional context:
Related but different (closed): #12006, #12134. Those crashed in GetBytesResponse::ProcessBody (buffer
handling, fixed in 11.6.1 / #12185); this one is a lifetime issue of the StorageReference and still
occurs on 12.4.10.
Firebase Core version
4.15.2
Flutter Version
3.41.4
Relevant Log Output
flutter run -d windows:
...
SyncService: processing 0 groups, 0 athletes, 0 custom_tests, 193 results, 40 wellness, 1 competitions
Lost connection to device.
Windows Event Viewer (Application Error), identical on every crash:
Faulting application: kinesense_app.exe (Debug build)
Faulting module: kinesense_app.exe (Firebase C++ SDK is statically linked)
Exception code: 0xc0000005
Fault offset: 0x000000000188a614 -> firebase::Mutex::Acquire
Crashing thread, symbolized from a WER full dump with the PDB:
firebase::Mutex::Acquire
firebase::MutexLock::MutexLock
firebase::FutureManager::GetFutureApi
firebase::storage::internal::StorageReferenceInternal::future
firebase::storage::internal::StorageReferenceInternal::AsyncSendRequestWithRetry<unsigned __int64>
std::invoke<... StorageReferenceInternal::* ...>
std::thread::_Invoke<... StorageReferenceInternal ...>
Flutter dependencies
Expand Flutter dependencies snippet
Dart SDK 3.11.1
Flutter SDK 3.41.4
kinesense_app 1.0.2+75
dependencies:
- archive 4.0.9 [path posix]
- cloud_firestore 6.10.2 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- confetti 0.7.0 [flutter vector_math]
- crypto 3.0.7 [typed_data]
- cupertino_icons 1.0.8
- drift 2.32.0 [async convert collection meta stream_channel sqlite3 path stack_trace web]
- file_selector 1.1.0 [file_selector_android file_selector_ios file_selector_linux file_selector_macos file_selector_platform_interface file_selector_web file_selector_windows flutter]
- firebase_auth 6.7.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 4.15.2 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_storage 13.6.1 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter mime]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_animate 4.5.2 [flutter flutter_shaders]
- flutter_rust_bridge 2.11.1 [args async build_cli_annotations meta path web]
- flutter_soloud 3.5.4 [ffi flutter http logging meta path path_provider plugin_platform_interface web]
- flutter_staggered_grid_view 0.7.0 [flutter]
- flutter_tts 4.2.5 [flutter flutter_web_plugins]
- freezed_annotation 3.1.0 [collection json_annotation meta]
- go_router 16.3.0 [collection flutter flutter_web_plugins logging meta]
- google_sign_in 6.3.0 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- kine_charts 0.1.0 [flutter image vector_math]
- package_info_plus 8.3.1 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock]
- path 1.9.1
- path_provider 2.1.5 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- rust_lib_kinesense 0.0.1 [flutter flutter_rust_bridge]
- share_plus 12.0.2 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi web win32]
- shared_preferences 2.5.4 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- sign_in_with_apple 7.0.1 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web]
- sqlite3_flutter_libs 0.5.42 [flutter]
- uuid 4.5.3 [crypto fixnum]
dev dependencies:
- build_runner 2.12.2 [analyzer args async build build_config build_daemon built_collection built_value code_builder collection convert crypto dart_style glob graphs http_multi_server io json_annotation logging meta mime package_config path pool pub_semver shelf shelf_web_socket stream_transform watcher web_socket_channel yaml]
- drift_dev 2.32.0 [charcode collection recase meta path json_annotation stream_transform args logging cli_util yaml io drift sqlite3 sqlparser analyzer source_span package_config pub_semver build build_config dart_style source_gen string_scanner]
- ffigen 19.1.0 [args cli_util collection dart_style ffi file glob logging meta package_config path pub_semver quiver yaml yaml_edit]
- flutter_lints 6.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing collection meta stream_channel]
- freezed 3.2.5 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation dart_style pub_semver]
- integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service]
- mocktail 1.0.5 [collection matcher test_api]
- sqlite3 3.5.2 [collection ffi meta path web typed_data hooks code_assets native_toolchain_c crypto]
transitive dependencies:
- _fe_analyzer_shared 93.0.0 [meta source_span]
- _flutterfire_internals 1.3.77 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 10.0.1 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- args 2.7.0
- async 2.13.0 [collection meta]
- boolean_selector 2.1.2 [source_span string_scanner]
- build 4.0.4 [analyzer crypto glob logging package_config path]
- build_cli_annotations 2.1.1 [args meta]
- build_config 1.3.0 [checked_yaml json_annotation path pubspec_parse]
- build_daemon 4.1.1 [built_collection built_value crypto http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- built_collection 5.1.1
- built_value 8.12.4 [built_collection collection fixnum meta]
- characters 1.4.1
- charcode 1.4.0
- checked_yaml 2.0.4 [json_annotation source_span yaml]
- cli_util 0.4.2 [meta path]
- clock 1.1.2
- cloud_firestore_platform_interface 8.0.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 5.7.3 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- code_assets 1.0.0 [collection hooks]
- code_builder 4.11.1 [built_collection built_value collection matcher meta]
- collection 1.19.1
- convert 3.1.2 [typed_data]
- cross_file 0.3.5+2 [meta web]
- dart_style 3.1.7 [analyzer args collection package_config path pub_semver source_span yaml]
- fake_async 1.3.3 [clock collection]
- ffi 2.2.0
- file 7.0.1 [meta path]
- file_selector_android 0.5.2+6 [file_selector_platform_interface flutter meta plugin_platform_interface]
- file_selector_ios 0.5.3+6 [file_selector_platform_interface flutter meta]
- file_selector_linux 0.9.4+1 [cross_file file_selector_platform_interface flutter meta]
- file_selector_macos 0.9.5+1 [cross_file file_selector_platform_interface flutter meta]
- file_selector_platform_interface 2.7.0 [cross_file flutter http plugin_platform_interface]
- file_selector_web 0.9.5 [file_selector_platform_interface flutter flutter_web_plugins web]
- file_selector_windows 0.9.3+6 [cross_file file_selector_platform_interface flutter meta]
- firebase_auth_platform_interface 9.1.0 [_flutterfire_internals collection firebase_core flutter http meta plugin_platform_interface]
- firebase_auth_web 6.3.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core_platform_interface 8.1.1 [collection flutter meta plugin_platform_interface]
- firebase_core_web 3.12.0 [firebase_core_platform_interface meta web]
- firebase_storage_platform_interface 6.0.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.11.13 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http meta web]
- fixnum 1.1.1
- flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver matcher]
- flutter_shaders 0.1.3 [flutter vector_math]
- flutter_web_plugins 0.0.0 [flutter]
- fuchsia_remote_debug_protocol 0.0.0 [process vm_service meta]
- glob 2.1.3 [async collection file path string_scanner]
- google_identity_services_web 0.3.3+1 [meta web]
- google_sign_in_android 6.2.1 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.9.0 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.5.0 [flutter plugin_platform_interface]
- google_sign_in_web 0.12.4+4 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http web]
- graphs 2.3.2 [collection]
- hooks 1.0.2 [collection crypto logging meta pub_semver yaml]
- http 1.6.0 [async http_parser meta web]
- http_multi_server 3.2.2 [async]
- http_parser 4.1.2 [collection source_span string_scanner typed_data]
- image 4.9.1 [archive xml]
- io 1.0.5 [meta path string_scanner]
- json_annotation 4.11.0 [meta]
- leak_tracker 11.0.2 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.10 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.2 [leak_tracker matcher meta]
- lints 6.1.0
- logging 1.3.0
- matcher 0.12.19 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.13.0 [collection]
- meta 1.17.0
- mime 2.0.0
- native_toolchain_c 0.17.5 [code_assets glob hooks logging meta pub_semver]
- objective_c 9.3.0 [code_assets collection ffi hooks logging native_toolchain_c pub_semver]
- package_config 2.2.0 [path]
- package_info_plus_platform_interface 3.2.1 [flutter meta plugin_platform_interface]
- path_provider_android 2.2.22 [flutter path_provider_platform_interface]
- path_provider_foundation 2.6.0 [ffi flutter objective_c path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- petitparser 7.0.2 [meta collection]
- platform 3.1.6
- plugin_platform_interface 2.1.8 [meta]
- pool 1.5.2 [async stack_trace]
- posix 6.5.0 [ffi meta path]
- process 5.0.6 [file path platform]
- pub_semver 2.2.0 [collection]
- pubspec_parse 1.5.0 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.2.2 [matcher]
- recase 4.1.0
- share_plus_platform_interface 6.1.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid]
- shared_preferences_android 2.4.21 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.5.6 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.4.3 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.2 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 3.0.0 [shelf stream_channel web_socket_channel]
- sign_in_with_apple_platform_interface 2.0.0 [flutter plugin_platform_interface meta]
- sign_in_with_apple_web 3.0.0 [flutter flutter_web_plugins sign_in_with_apple_platform_interface]
- sky_engine 0.0.0
- source_gen 4.2.0 [analyzer async build dart_style glob path pub_semver source_span yaml]
- source_span 1.10.2 [collection path term_glyph]
- sqlparser 0.44.2 [meta collection source_span charcode]
- stack_trace 1.12.1 [path]
- stream_channel 2.1.4 [async]
- stream_transform 2.1.1
- string_scanner 1.4.1 [source_span]
- sync_http 0.3.1
- term_glyph 1.2.2
- test_api 0.7.10 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- typed_data 1.4.0 [collection]
- url_launcher_linux 3.2.2 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface]
- url_launcher_web 2.4.2 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.5 [flutter url_launcher_platform_interface]
- vector_math 2.2.0
- vm_service 15.0.2
- watcher 1.2.1 [async path]
- web 1.1.1
- web_socket 1.0.1 [web]
- web_socket_channel 3.0.3 [async crypto stream_channel web web_socket]
- webdriver 3.2.0 [matcher path stack_trace sync_http web]
- win32 5.15.0 [ffi]
- xdg_directories 1.1.0 [meta path]
- xml 7.0.1 [collection meta petitparser]
- yaml 3.1.3 [collection source_span string_scanner]
- yaml_edit 2.2.4 [collection meta source_span yaml]```
</details>
### Additional context and comments
_No response_
- Dominant language
- Dart
- Stars
- 9.3k
- Forks
- 4.1k
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 49
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/flutterfire
-
[cloud_functions]: Apple platforms ignore custom domains passed as regionPossibly taken @ragavendranbala-TSL claimed this today. OpenNeeds Attention platform: ios platform: macos plugin: functions type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/flutterfire#19015 · 2 comments ·
Maintainers usually reply within 4 days
-
Needs Attention platform: android plugin: messaging type: bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
firebase/flutterfire#19017 ·
Maintainers usually reply within 4 days
-
Needs Attention platform: web plugin: crashlytics type: enhancement
Difficulty 5/5 Over a week Newbie friendliness 34/100
firebase/flutterfire#19014 · 1 comment ·
Maintainers usually reply within 4 days
-
[firebase_messaging]: Android getToken() errors lose their cause since firebase-messaging 25.1.0 ("FCM Registration failed!")Possibly taken @SelaseKay claimed this 3 days ago. OpenNeeds Attention platform: android plugin: messaging reproduced type: bug
Difficulty 4/5 3-5 days Newbie friendliness 22/100
firebase/flutterfire#18997 · 1 comment ·
Maintainers usually reply within 4 days
-
[firebase_auth_web]: Make the Auth emulator persistence from #18926 configurable instead of hard-gated on kDebugModePossibly taken @SelaseKay claimed this 1 day ago. OpenNeeds Attention platform: web plugin: auth type: enhancement
Difficulty 3/5 1-2 days Newbie friendliness 62/100
firebase/flutterfire#18992 · 1 comment ·
Maintainers usually reply within 4 days
All issues in firebase/flutterfire
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hajisensai/Fushi#4543 · 3 comments ·
Maintainers usually reply within 1 day
-
[video_player] _updatePosition sets isCompleted=true after 500ms when duration is Duration.zeroOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
chriskelly/wish-together#212 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
spotiflacapp/SpotiFLAC-Mobile#984 ·