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

DataStore is syncing with large delay #5458

Open
2 of 14 tasks
olena1911 opened this issue Sep 16, 2024 · 5 comments
Open
2 of 14 tasks

DataStore is syncing with large delay #5458

olena1911 opened this issue Sep 16, 2024 · 5 comments
Labels
datastore Issues related to the DataStore Category question A question about the Amplify Flutter libraries

Comments

@olena1911
Copy link

Description

When I modify some entity in DataStore (either add a new one to the table or remove), the updates on the cloud are made with a delay (sometimes it's several minutes, sometimes it's up to several hours). Initial sync when DataStore is started is successful, but updates to the cloud takes more time than expected.

It seems that the problem is only on Android. From our experiments, iOS works fine.

Can it be a bug or some additional configurations should be made?

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. Configure DataStore (I use injectable to provide an instance of DataStore):
@module
abstract class AmplifyDataStoreModule {
  @lazySingleton
  @preResolve
  Future<AmplifyDataStore> initAmplifyDataStore(
    DeviceInfoRepository deviceInfoRepository,
  ) async {
    return AmplifyDataStore(
      modelProvider: ModelProvider.instance,
      options: DataStorePluginOptions(
        syncExpressions: [
          // some sync expressions, but sync doesn't work without them neither
        ],
      ),
    );
  }
}
  1. Configure Amplify (other plugins are provided via DI)
Future<void> _configurePlugins() async {
    await Amplify.addPlugins([
      _amplifyAuthCognito,
      _amplifyAPI,
      _amplifyStorageS3,
      _amplifyDataStore,
    ]);

    await Amplify.configure(amplifyconfig);
  }
  1. Start DataStore sync
    await _amplifyDataStore.start();

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.22.2

Amplify Flutter Version

2.1.0

Deployment Method

Amplify CLI (Gen 1)

Schema

No response

@github-actions github-actions bot added pending-triage This issue is in the backlog of issues to triage pending-maintainer-response Pending response from a maintainer of this repository labels Sep 16, 2024
@Equartey
Copy link
Contributor

Hi @olena1911, sorry to hear your data syncs are taking longer than on Android.

This seems unexpected. Although I do not have experience with the decorators you are using, your plugin configuration looks okay.

I would suggest trying to update to the latest version of Amplify DataStore, 2.4.1.

If the problem persists, can you provide your schema and any logs from the delayed sync?

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Sep 16, 2024
@Equartey Equartey added datastore Issues related to the DataStore Category pending-community-response Pending response from the issue opener or other community members labels Sep 16, 2024
@olena1911
Copy link
Author

Hi @Equartey , thanks for your reply. It's hard to catch related logs. I found something but I'm not sure if it's related. There is an attempt to make a mutation after adding data, but it fails

10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: Attempt #1 failed.
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: DataStoreException{message=Failure during mutation., cause=ApiException{message=OkHttp client failed to make a successful request., cause=ApiAuthException{message=Failed to retrieve auth token from Cognito provider., cause=ApiAuthException{message=No native plugin registered, cause=null, recoverySuggestion=Sorry, we don't have a recovery suggestion for this error.}, recoverySuggestion=Check the application logs for details.}, recoverySuggestion=Sorry, we don't have a recovery suggestion for this error.}, recoverySuggestion=Check details.}
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$mutation$4(Unknown Source:6)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.datastore.appsync.AppSyncClient.c(Unknown Source:0)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.auth.a.accept(Unknown Source:12)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.AppSyncGraphQLOperation.dispatchRequest(SourceFile:6)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.AppSyncGraphQLOperation.a(Unknown Source:0)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.d.run(Unknown Source:18)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at java.lang.Thread.run(Thread.java:1012)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: Caused by: ApiException{message=OkHttp client failed to make a successful request., cause=ApiAuthException{message=Failed to retrieve auth token from Cognito provider., cause=ApiAuthException{message=No native plugin registered, cause=null, recoverySuggestion=Sorry, we don't have a recovery suggestion for this error.}, recoverySuggestion=Check the application logs for details.}, recoverySuggestion=Sorry, we donΓÇÖt have a recovery suggestion for this error.}
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	... 8 more
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: Caused by: ApiAuthException{message=Failed to retrieve auth token from Cognito provider., cause=ApiAuthException{message=No native plugin registered, cause=null, recoverySuggestion=Sorry, we don't have a recovery suggestion for this error.}, recoverySuggestion=Check the application logs for details.}
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.auth.ApiRequestDecoratorFactory.forAuthType(Unknown Source:263)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.auth.ApiRequestDecoratorFactory.fromGraphQLRequest(Unknown Source:18)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.AppSyncGraphQLOperation.dispatchRequest(Unknown Source:42)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	... 7 more
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: Caused by: ApiAuthException{message=No native plugin registered, cause=null, recoverySuggestion=Sorry, we don't have a recovery suggestion for this error.}
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider.fetchToken(Unknown Source:41)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider.getLatestAuthToken(Unknown Source:0)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	at com.amplifyframework.api.aws.auth.ApiRequestDecoratorFactory.forAuthType(Unknown Source:243)
10-01 11:51:05.517 16359 18951 W amplify:aws-datastore: 	... 9 more

@github-actions github-actions bot added pending-maintainer-response Pending response from a maintainer of this repository and removed pending-community-response Pending response from the issue opener or other community members labels Oct 13, 2024
@NikaHsn
Copy link
Member

NikaHsn commented Oct 14, 2024

@olena1911 thanks for providing the error logs.

have you been able to upgrade to latest version of Amplify DataStore and if this log message if from the latest version?

Based on the logs it seems that the app can not fetch the auth token and so the mutation request to appsync is failing. In this case we should anticipate continuous sync failures rather than intermittent delays.

can you please confirm if the logs are for the delayed sync issue and also provide your schema so that we can reproduce this issue?

thanks.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Oct 14, 2024
@NikaHsn NikaHsn added pending-community-response Pending response from the issue opener or other community members question A question about the Amplify Flutter libraries and removed pending-triage This issue is in the backlog of issues to triage labels Oct 14, 2024
@HarkerTech
Copy link

Hi, we have hit this issue with amplify_datastore v2.5.0 when the app is destroyed in the background on Android. This can be replicated using by enabling "Don't keep activities". When trying to update Datastore after the activity is re-created after being destroyed the "Failed to retrieve auth token from Cognito provider." exception occurs.

@github-actions github-actions bot added pending-maintainer-response Pending response from a maintainer of this repository and removed pending-community-response Pending response from the issue opener or other community members labels Nov 7, 2024
@NikaHsn
Copy link
Member

NikaHsn commented Nov 18, 2024

@HarkerTech would you be able to share the error message you receive. would you please confirm if the user is authenticated and also if there is a network connection?

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category question A question about the Amplify Flutter libraries
Projects
None yet
Development

No branches or pull requests

4 participants