Amplify-ios: [iOS] After `signIn` flow, the `Amplify.Hub` .dataStore channel doesn't emit the `ready` event after all data loaded

Created on 26 Apr 2021  路  6Comments  路  Source: aws-amplify/amplify-ios

Describe the bug
When an existing user logs back in (signIn) the dataStore doesn't emit the ready
as per handling waiting as: Amplify.Hub.listen(to: .dataStore)

To Reproduce
Steps to reproduce the behavior:

  1. Configure plugins: dataStore, cognito, API and S3Storage and call Amplify.configure
  2. Authenticate an existing user through Amplify.Auth.signIn
  3. listen dataStore channel via Amplify.HUB.listen
  4. wait all models get pulled into the device and ... no ready is called

Expected behaviour
I expect the HubPayload.EventName.DataStore.ready aka "DataStore.ready" to be emitted by the HUB after all data gets pulled into the device for that user to kindly update UI.
As docs states here

Environment(please complete the following information):

  • Amplify (1.8.1):

    • AmplifyPlugins/AWSAPIPlugin (1.8.1):



      • AWSCore (~> 2.23.3)


      • AWSPluginsCore (= 1.8.1)


      • AWSAuthCore (~> 2.23.3)


      • AWSCognitoIdentityProvider (~> 2.23.3)


      • AWSCognitoIdentityProviderASF (~> 2.23.3)


      • AWSMobileClient (~> 2.23.3)



    • AmplifyPlugins/AWSDataStorePlugin (1.8.1):



      • SQLite.swift (~> 0.12.0)


      • AWSS3 (~> 2.23.3)



    • AppSyncRealTimeClient (1.4.4):



      • Starscream (~> 3.1.1)



    • AWSAuthCore (2.23.4):

    • AWSCognitoIdentityProvider (2.23.4):



      • AWSCognitoIdentityProviderASF (= 2.23.4)



    • AWSCognitoIdentityProviderASF (2.23.4)

    • AWSMobileClient (2.23.4):



      • AWSAuthCore (= 2.23.4)


      • AWSCognitoIdentityProvider (= 2.23.4)


      • AWSCognitoIdentityProviderASF (= 2.23.4)



    • AWSS3 (2.23.4):

  • Dependency Manager: Cocoapods

Device Information (please complete the following information):

  • Any device or Simulator iOS12+

Additional context

  • just opening the app previously synced emits ready
  • when users signUp also works fine, dataStore also emits ready
  • when there's an user logged we call signOut on Cognito and Amplify.DataStore.clear in order to log back in

Thank you
Any help is really appreciated 馃憤

bug datastore follow up

All 6 comments

I've also tried uninstalling before to make sure the clear step wan't interfering but the result is the same

Also I've made a not-so-good workaround where right after I listen the HUB events, I call:

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
      Amplify.DataStore.stop { result in
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
          Amplify.DataStore.start {
            print("-> started \($0)")
          }
        }
      }
    }

so that after the sync, it reloads all events from the API (way faster) and finally the ready is emitted.
I'm looking forward to delete that. 馃槄

This may be related to orphaned items. I've described that here. You may want to check if you have items where the parent is missing.

Also I've made a not-so-good workaround where right after I listen the HUB events, I call:

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
      Amplify.DataStore.stop { result in
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
          Amplify.DataStore.start {
            print("-> started \($0)")
          }
        }
      }
    }

so that after the sync, it reloads all events from the API (way faster) and finally the ready is emitted.
I'm looking forward to delete that. 馃槄

I believe I noticed a similar issue when I was trying to do this, I couldn't call start from the completion of the stop, because stop's completion actually hasn't completely finished stopping the sync engine. documented my findings over here: https://github.com/aws-amplify/amplify-ios/issues/1177 what you've done here is the workaround until we fix the stop then start issue

@dsaliberti could you provide us some details as to

  • what type of models do you have in your schema? i'd like to understand how you're annotating the models, ie. with @auth directive, type of connections between models, etc.
  • what auth type are you using for the API?
  • can you clarify when you are calling DataStore.clear? is it when the user signs out? If so, you can call DataStore.start when the user signs back in, does this not work for you such that the ready event does not fire? Do you see any error logs with Amplify.Logging.logLevel = .verbose enabled?

what type of models do you have in your schema? i鈥檇 like to understand how you鈥檙e annotating the models, ie. with @auth directive, type of connections between models, etc.

We use only simple models without any other annotation than @auth - no relation between objects

what auth type are you using for the API?

we use Cognito authentication via Amplify Plugin

can you clarify when you are calling DataStore.clear

sure, as soon as the user signOut with success, we call clear.

Amplify.Auth.signOut(...
      switch result {
      case .success:
        ...
        Amplify.DataStore.clear { result in

but don't call start after wise. Only when an authentication happens, and "home" screen is loaded, we call start again.
I think we could try that now.
There is a log I see for a while now and I think it is relevant:

handleDataEvent(response:): ignoring data event for 2AEBD7A9-4AB7-44FB-93E1-DF5CCD531FAE

and I can see it's from
extension AppSyncSubscriptionConnection / func handleDataEvent(response: AppSyncResponse)
I hope it helps

Was this page helpful?
0 / 5 - 0 ratings