amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

Datastore Hub Channel failing to emit "ready" hubEvent after calling Datastore.start() on Android

Open djsjr opened this issue 3 years ago • 7 comments

Description

Occasionally (I have trouble reproducing it consistently) Datastore Hub Channel on Android will fail to emit the hubEvent "ready". I cannot say for certain that datastore isn't syncing fully. It stops after emitting several "modelSynced" events, which makes me think that it has all but finished.

Again, I have trouble reproducing this consistently, but it happens on an ongoing basis.

Categories

  • [ ] Analytics
  • [ ] API (REST)
  • [ ] API (GraphQL)
  • [ ] Auth
  • [ ] Authenticator
  • [X] DataStore
  • [ ] Storage

Steps to Reproduce

  1. Run this:
      StreamSubscription? hubSubscription;
      await Amplify.DataStore.stop();
      await Amplify.DataStore.start();

      hubSubscription =
          Amplify.Hub.listen([HubChannel.DataStore], (hubEvent) async {
              print(hubEvent.eventName);
          }
        );
  1. Observe hubEvents as they're emitted.
  2. Occasionally get stuck on "modelSynced" event after several others "modelSynced" events have printed
  3. Never observe a "ready" event as expected

Screenshots

No response

Platforms

  • [ ] iOS
  • [X] Android

Android Device/Emulator API Level

No response

Environment

[✓] Flutter (Channel stable, 3.0.2, on macOS 12.0.1 21A559 darwin-arm, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.69.0)
[✓] Connected device (4 available)
    ! Error: iPhone is not connected. Xcode will continue when iPhone is connected. (code -13)
    ! Error: iPhone is not connected. Xcode will continue when iPhone is connected. (code -13)
[✓] HTTP Host Availability

• No issues found!

Dependencies

Dart SDK 2.17.6
Flutter SDK 3.0.5
see_app 3.1.7+97

dependencies:
- adaptive_dialog 1.6.4+2 [animations collection dynamic_color flutter intersperse macos_ui meta]
- amplify_analytics_pinpoint 0.6.3 [amplify_analytics_pinpoint_android amplify_analytics_pinpoint_ios amplify_core aws_common flutter meta]
- amplify_api 0.6.3 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.3 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_core 0.6.3 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore 0.6.3 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.6.3 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- amplify_storage_s3 0.6.3 [amplify_storage_s3_android amplify_storage_s3_ios amplify_core aws_common flutter meta plugin_platform_interface]
- async 2.8.2 [collection meta]
- audio_service 0.18.7 [audio_service_platform_interface audio_service_web audio_session rxdart flutter_cache_manager clock js flutter flutter_web_plugins]
- audio_session 0.1.10 [flutter flutter_web_plugins rxdart meta]
- back_button_interceptor 6.0.1 [collection flutter]
- badges 2.0.3 [flutter]
- chewie 1.3.4 [cupertino_icons flutter provider video_player wakelock]
- connectivity_plus 2.3.6 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows]
- cupertino_icons 1.0.5
- email_validator 2.0.1
- firebase_core 1.20.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 12.0.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_app_badger 1.4.0 [flutter]
- flutter_keyboard_visibility 5.3.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
- http 0.13.4 [async http_parser meta path]
- intl 0.17.0 [clock path]
- just_audio 0.9.28 [just_audio_platform_interface just_audio_web audio_session rxdart path path_provider async uuid crypto meta flutter]
- keyboard_dismisser 3.0.0 [flutter]
- persistent_bottom_nav_bar 4.0.2 [flutter]
- provider 6.0.3 [collection flutter nested]
- readmore 2.2.0 [flutter]
- shape_of_view_null_safe 2.0.0 [flutter vector_math]
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- simple_rich_text 2.0.49 [flutter url_launcher]
- video_player 2.4.5 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]
- visibility_detector 0.3.3 [flutter]
- webview_flutter 3.0.4 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview]

transitive dependencies:
- amplify_analytics_pinpoint_android 0.6.3 [flutter]
- amplify_analytics_pinpoint_ios 0.6.3 [flutter]
- amplify_api_android 0.6.3 [flutter]
- amplify_api_ios 0.6.3 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.3 [flutter]
- amplify_auth_cognito_ios 0.6.3 [amplify_core flutter]
- amplify_datastore_plugin_interface 0.6.3 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.3 [flutter]
- amplify_flutter_ios 0.6.3 [amplify_core flutter]
- amplify_storage_s3_android 0.6.3 [flutter]
- amplify_storage_s3_ios 0.6.3 [flutter]
- animations 2.0.3 [flutter]
- args 2.3.1
- audio_service_platform_interface 0.1.0 [flutter plugin_platform_interface meta]
- audio_service_web 0.1.1 [audio_service_platform_interface rxdart js flutter flutter_web_plugins]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- connectivity_plus_linux 1.3.1 [flutter connectivity_plus_platform_interface meta nm]
- connectivity_plus_macos 1.2.4 [connectivity_plus_platform_interface flutter]
- connectivity_plus_platform_interface 1.2.1 [flutter meta plugin_platform_interface]
- connectivity_plus_web 1.2.3 [connectivity_plus_platform_interface flutter_web_plugins flutter]
- connectivity_plus_windows 1.2.2 [connectivity_plus_platform_interface flutter]
- crypto 3.0.2 [typed_data]
- csslib 0.17.2 [source_span]
- dbus 0.7.7 [args ffi meta xml]
- dynamic_color 1.4.0 [flutter flutter_test material_color_utilities]
- fake_async 1.3.0 [clock collection]
- ffi 2.0.1
- file 6.1.2 [meta path]
- firebase_core_platform_interface 4.5.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 1.7.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 4.1.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.1.0 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- html 0.15.0 [csslib source_span]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- intersperse 2.0.0
- js 0.6.4
- json_annotation 4.6.0 [meta]
- just_audio_platform_interface 4.2.0 [flutter plugin_platform_interface]
- just_audio_web 0.4.7 [just_audio_platform_interface flutter flutter_web_plugins]
- macos_ui 1.7.0 [flutter]
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- nested 1.0.0 [flutter]
- nm 0.5.0 [dbus]
- path 1.8.1
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.16 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.10 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.0 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- petitparser 5.0.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- rxdart 0.27.5
- shared_preferences_android 2.0.12 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- sqflite 2.0.3 [flutter sqflite_common path]
- sqflite_common 2.2.1+1 [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+2
- term_glyph 1.2.0
- test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.1 [collection]
- url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- url_launcher_android 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface]
- url_launcher_web 2.0.12 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- video_player_android 2.3.8 [flutter video_player_platform_interface]
- video_player_avfoundation 2.3.5 [flutter video_player_platform_interface]
- video_player_platform_interface 5.1.3 [flutter plugin_platform_interface]
- video_player_web 2.0.12 [flutter flutter_web_plugins video_player_platform_interface]
- wakelock 0.6.2 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows]
- wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface]
- wakelock_platform_interface 0.3.0 [flutter meta]
- wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface]
- wakelock_windows 0.2.0 [flutter wakelock_platform_interface win32]
- webview_flutter_android 2.9.2 [flutter webview_flutter_platform_interface]
- webview_flutter_platform_interface 1.9.1 [flutter meta plugin_platform_interface]
- webview_flutter_wkwebview 2.9.1 [flutter path webview_flutter_platform_interface]
- win32 2.7.0 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 6.1.0 [collection meta petitparser]

Device

Motorola G Power

OS

Android 11

CLI Version

9.1.0

Additional Context

No response

djsjr avatar Jul 25 '22 03:07 djsjr

Hi @djsjr there is a known issue in amplify-android that calling clear and start back to back may cause failures in the start call. As stop executes similar steps as clear, this issue may also cause what you are seeing.

Can you try to add a manual delay between the stop and start calls see if it mitigates? e.g.

await Amplify.DataStore.stop();
await Future.delay(const Duration(seconds: 1));
await Amplify.DataStore.start();

HuiSF avatar Jul 25 '22 16:07 HuiSF

I started seeing this issue as well. For me, I'm testing ios app on simulator.

Code:

StreamSubscription dsHub =
  Amplify.Hub.listen([HubChannel.DataStore], (hubEvent) {
});
dsHub.onData((data) async {
  if (data.eventName == 'ready') {
    getProfile();
    await dsHub.cancel();
  } else {
    print(data.eventName);
  } 
});

Output:

flutter: syncQueriesStarted
7
flutter: modelSynced
flutter: syncQueriesStarted
7
flutter: modelSynced
flutter: syncQueriesStarted
7
flutter: modelSynced
flutter: syncQueriesStarted
7
flutter: modelSynced
flutter: syncQueriesStarted
7
flutter: modelSynced
flutter: syncQueriesStarted
7
flutter: modelSynced
flutter: syncQueriesStarted
7
flutter: modelSynced

It never gets to ready state. I only start to see this issue today. It used to work fine before. I recreated the environment several times with no luck.

skim037 avatar Jul 27 '22 05:07 skim037

@HuiSF Any problem with just leaving out the .stop() entirely? The docs say: "You can also force your DataStore sync expressions to be re-evaluated at runtime by calling stop() followed by start()."

When would this be used as opposed to just calling start? For my use case, which is syncing after signing up or signing in, it seems to work without calling .stop() first.

djsjr avatar Jul 27 '22 19:07 djsjr

Are you trying to reevaluate sync expression? Or just wanting to start DataStore after user signed in? If the latter, you don't need to invoke stop() prior calling start().

Please let know if getting rid of stop() or adding a delay mitigates the issue you encountered @djsjr thank you :)

HuiSF avatar Jul 27 '22 19:07 HuiSF

Hi @skim037 I think I actually encountered an issue in amplify-ios that prevents emitting the ready event under certain circumstances (I don't remember exactly how did I produce that error). amplify-ios maintainers implemented a fix, I need to check when that fix will be released.

Updated: fix PR in amplify-ios https://github.com/aws-amplify/amplify-ios/pull/1989

HuiSF avatar Jul 27 '22 19:07 HuiSF

Are you trying to reevaluate sync expression? Or just wanting to start DataStore after user signed in? If the latter, you don't need to invoke stop() prior calling start().

Please let know if getting rid of stop() or adding a delay mitigates the issue you encountered @djsjr thank you :)

Ah I understand now. I had not been using selective sync because I wasn't sure how to reset that after sign in. I now understand that this is referring to just that situation. I will now begin using it with a delay between stop and start and see if that fixes things.

djsjr avatar Jul 27 '22 20:07 djsjr

Hi @HuiSF My issue seems unrelated to this. I created new bug #1936

skim037 avatar Jul 28 '22 09:07 skim037

Closing in favor of https://github.com/aws-amplify/amplify-flutter/issues/1479 . The original issue mentioned in the main post was caused by the same described in the linked issue.

HuiSF avatar Jan 09 '23 20:01 HuiSF