Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_storage] Task not completing when error #12008

Closed
Dampfwalze opened this issue Dec 9, 2023 · 6 comments · Fixed by #12160
Closed

🐛 [firebase_storage] Task not completing when error #12008

Dampfwalze opened this issue Dec 9, 2023 · 6 comments · Fixed by #12160
Assignees
Labels
plugin: storage resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@Dampfwalze
Copy link

Bug report

Specifically in the implementation for the native platform, a Task never completes its Future, when it results in an error.

Steps to reproduce

Disallow write access on your storage and try to write any file.

When you try to await the resulting task, it will never finish.

When you use Task.snapshotEvents.listen with an error handler, the handler gets called as normal.

Expected behavior

It should finish with an error.

Sample project

// with rule: "allow write: if false"
final task = FirebaseStorage.instance.ref().child("test.txt").putString("test");

task.snapshotEvents.listen((event) {
  print(event.bytesTransferred / event.totalBytes);
}, onError: (error, stackTrace) {
  print("Error in stream listener: $error");
}, onDone: () {
  print("done");
});

try {
  final result = await task;
  print(result); // This is never called
} catch (e) {
  print("Error after await: $e"); // This is never called
}

Additional context

I believe this is because the catch block on line 55 in the following code does not complete the completer, like on line 52. Though it should complete it with an error.

/// Creates a new [MethodChannelTask] with a given task.
MethodChannelTask(
this._handle,
this.storage,
String path,
this._initialTask,
) : super() {
Stream<TaskSnapshotPlatform> mapNativeStream() async* {
final observerId = await _initialTask;
final nativePlatformStream =
MethodChannelFirebaseStorage.storageTaskChannel(observerId)
.receiveBroadcastStream();
try {
await for (final events in nativePlatformStream) {
final taskState = TaskState.values[events['taskState']];
if (_snapshot.state != TaskState.canceled) {
MethodChannelTaskSnapshot snapshot = MethodChannelTaskSnapshot(
storage,
taskState,
Map<String, dynamic>.from(events['snapshot']));
_snapshot = snapshot;
}
yield _snapshot;
// If the stream event is complete, trigger the
// completer to resolve with the snapshot.
if (snapshot.state == TaskState.success) {
_didComplete = true;
_completer?.complete(snapshot);
}
}
} catch (exception, stack) {
convertPlatformException(exception, stack);
}
}
_stream = mapNativeStream().asBroadcastStream(
onListen: (sub) => sub.resume(), onCancel: (sub) => sub.pause());
// Keep reference to whether the initial "start" task has completed.
_snapshot = MethodChannelTaskSnapshot(storage, TaskState.running, {
'path': path,
'bytesTransferred': 0,
'totalBytes': 1,
});
}


Flutter doctor

Click To Expand
[√] Flutter (Channel stable, 3.16.2, on Microsoft Windows [Version 10.0.19045.3693], locale de-DE)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.6)
[√] Android Studio (version 2021.1)
[√] VS Code (version 1.85.0)
[√] Connected device (5 available)
[√] Network resources

• No issues found!

Flutter dependencies

Click To Expand
Dart SDK 3.2.2
Flutter SDK 3.16.2
dapp_collection_app 1.0.0+1

dependencies:
- camera 0.10.5+6 [camera_android camera_avfoundation camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle]
- cloud_firestore 4.13.5 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- connectivity_plus 5.0.2 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm]
- cupertino_icons 1.0.6
- firebase_auth 4.15.2 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 2.24.2 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_storage 11.5.5 [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 web sky_engine]
- flutter_riverpod 2.4.9 [collection flutter meta riverpod state_notifier]
- flutter_signin_button 2.0.0 [flutter font_awesome_flutter]
- freezed_annotation 2.4.1 [collection json_annotation meta]
- google_sign_in 6.1.6 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- json_annotation 4.8.1 [meta]
- path 1.8.3
- path_provider 2.1.1 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- shared_preferences 2.2.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- uuid 4.2.1 [crypto sprintf meta]

dev dependencies:
- build_runner 2.4.7 [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]
- custom_lint 0.5.7 [analyzer analyzer_plugin args async ci cli_util collection freezed_annotation json_annotation meta package_config path pub_semver pubspec_parse rxdart uuid yaml]
- flutter_lints 3.0.1 [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]
- freezed 2.4.5 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation]
- json_serializable 6.7.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
- riverpod_lint 2.3.7 [analyzer analyzer_plugin collection custom_lint_builder meta path riverpod riverpod_analyzer_utils source_span yaml]      

transitive dependencies:
- _fe_analyzer_shared 64.0.0 [meta]
- _flutterfire_internals 1.3.16 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 6.2.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- analyzer_plugin 0.11.3 [analyzer collection dart_style pub_semver yaml]
- args 2.4.2
- async 2.11.0 [collection meta]
- 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.1 [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.1 [analyzer async build collection convert crypto graphs logging package_config path pool pub_semver stream_transform yaml]- build_runner_core 7.2.11 [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.8.0 [built_collection collection fixnum meta]
- camera_android 0.10.8+14 [camera_platform_interface flutter flutter_plugin_android_lifecycle stream_transform]
- camera_avfoundation 0.9.13+7 [camera_platform_interface flutter stream_transform]
- camera_platform_interface 2.6.0 [cross_file flutter plugin_platform_interface stream_transform]
- camera_web 0.3.2+3 [camera_platform_interface flutter flutter_web_plugins stream_transform]
- characters 1.3.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- ci 0.1.0
- cli_util 0.4.0 [meta path]
- clock 1.1.1
- cloud_firestore_platform_interface 6.0.9 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 3.8.9 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- code_builder 4.8.0 [built_collection built_value collection matcher meta]
- collection 1.18.0
- connectivity_plus_platform_interface 1.2.4 [flutter meta plugin_platform_interface]
- convert 3.1.1 [typed_data]
- cross_file 0.3.3+8 [meta web]
- crypto 3.0.3 [typed_data]
- custom_lint_builder 0.5.7 [analyzer analyzer_plugin collection custom_lint custom_lint_core glob hotreloader meta path pubspec_parse rxdart]   
- custom_lint_core 0.5.7 [analyzer analyzer_plugin collection custom_lint matcher meta path pubspec_parse source_span yaml]
- dart_style 2.3.4 [analyzer args collection path pub_semver source_span]
- dbus 0.7.10 [args ffi meta xml]
- fake_async 1.3.1 [clock collection]
- ffi 2.1.0
- file 7.0.0 [meta path]
- firebase_auth_platform_interface 7.0.8 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.8.11 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta]    
- firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.10.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 5.1.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.6.17 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.1.0
- flutter_plugin_android_lifecycle 2.0.17 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web]
- font_awesome_flutter 9.2.0 [flutter]
- frontend_server_client 3.2.0 [async path]
- glob 2.1.2 [async collection file path string_scanner]
- google_identity_services_web 0.2.2 [js meta]
- google_sign_in_android 6.1.20 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.6.3 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.4.3 [flutter plugin_platform_interface]
- google_sign_in_web 0.12.2+1 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js]
- graphs 2.3.1 [collection]
- hotreloader 4.1.0 [collection logging path stream_transform vm_service watcher]
- http 1.1.2 [async http_parser meta web]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- io 1.0.4 [meta path string_scanner]
- js 0.6.7 [meta]
- lints 3.0.0
- logging 1.2.0
- matcher 0.12.16 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.5.0 [collection]
- meta 1.10.0
- mime 1.0.4
- nm 0.5.0 [dbus]
- package_config 2.1.0 [path]
- path_provider_android 2.2.1 [flutter path_provider_platform_interface]
- path_provider_foundation 2.3.1 [flutter 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.1 [flutter platform plugin_platform_interface]
- path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32]
- petitparser 6.0.2 [meta]
- platform 3.1.3
- plugin_platform_interface 2.1.7 [meta]
- pool 1.5.1 [async stack_trace]
- pub_semver 2.1.4 [collection meta]
- pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml]
- riverpod 2.4.9 [meta stack_trace state_notifier]
- riverpod_analyzer_utils 0.5.0 [analyzer collection crypto custom_lint_core freezed_annotation meta path source_span]
- rxdart 0.27.7
- shared_preferences_android 2.2.1 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.3.4 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.3.2 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]  
- shared_preferences_platform_interface 2.3.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.2.2 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- 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 1.0.4 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_gen 1.4.0 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.4 [analyzer collection source_gen]
- source_span 1.10.0 [collection path term_glyph]
- sprintf 7.0.0
- stack_trace 1.11.1 [path]
- state_notifier 1.0.0 [meta]
- stream_channel 2.1.2 [async]
- stream_transform 2.1.0
- 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]
- timing 1.0.1 [json_annotation]
- typed_data 1.3.2 [collection]
- vector_math 2.1.4
- vm_service 13.0.0
- watcher 1.1.0 [async path]
- web 0.3.0
- web_socket_channel 2.4.0 [async crypto stream_channel]
- win32 5.1.1 [ffi]
- xdg_directories 1.0.3 [meta path]
- xml 6.5.0 [collection meta petitparser]
- yaml 3.1.2 [collection source_span string_scanner]

@Dampfwalze Dampfwalze added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Dec 9, 2023
@darshankawar darshankawar added the triage Issue is currently being triaged. label Dec 11, 2023
@darshankawar
Copy link

Thanks for the report @Dampfwalze
Can you take a look at this and check if it resembles your case or not ?

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Dec 11, 2023
@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label Dec 20, 2023
@google-oss-bot
Copy link

Hey @Dampfwalze. 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!

@Dampfwalze
Copy link
Author

@darshankawar I looked into that issue and, while beeing similar, it does not resemble my case. That issue is about the Task.snapshotEvents stream, which is never closed. My issue is about the Task itself, which inherits Future, so you can await it, but it will never be completed, if the operation, referenced by the Task results in an error.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. Stale Issue with no recent activity labels Dec 27, 2023
@darshankawar
Copy link

Thanks for the update and sorry for coming back late on this. Can you provide on which platform are you seeing this behavior ?

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 3, 2024
@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label Jan 12, 2024
@google-oss-bot
Copy link

Hey @Dampfwalze. 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!

@Dampfwalze
Copy link
Author

I tested this on Android, but this happens on all platforms using the method channel implementation, since the problem lies in the Dart layer, which is common to all of these platforms.

The web implementation seems to not have this issue. Wenn you look through the source code, the JS Promise returned by the JS firebase.storage library is pretty much directly piped to the Future exposed by the UploadTask and it seems like, this Promise will throw any errors correctly (I did not test this).

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed Stale Issue with no recent activity blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 12, 2024
@russellwheatley russellwheatley self-assigned this Jan 15, 2024
@darshankawar darshankawar added plugin: storage platform: android Issues / PRs which are specifically for Android. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. platform: android Issues / PRs which are specifically for Android. labels Jan 16, 2024
@darshankawar darshankawar added the resolution: fixed A fix has been merged or is pending merge from a PR. label Jan 18, 2024
@firebase firebase locked and limited conversation to collaborators Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: storage resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
4 participants