DataStore is syncing with large delay
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
- [X] DataStore
- [ ] Notifications (Push)
- [ ] Storage
Steps to Reproduce
- 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
],
),
);
}
}
- Configure Amplify (other plugins are provided via DI)
Future<void> _configurePlugins() async {
await Amplify.addPlugins([
_amplifyAuthCognito,
_amplifyAPI,
_amplifyStorageS3,
_amplifyDataStore,
]);
await Amplify.configure(amplifyconfig);
}
- Start DataStore sync
await _amplifyDataStore.start();
Screenshots
No response
Platforms
- [ ] iOS
- [X] 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
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?
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
@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.
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.
@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?
Hi @NikaHsn, apologies for the late reply. I can confirm the user was authenticated and network connection is active. After replicating the issue again the log message is below, there were further retry attempts but all failed with the same exception.
After pulling in the fix in https://github.com/aws-amplify/amplify-flutter/pull/5740 I could not reproduce the issue, thanks for looking into this.
I/amplify:aws-datastore( 5547): Started Publish with retry: PendingMutation{mutatedItem=SerializedModel{id='...', serializedData={...}, mutationType=UPDATE, mutationId=..., predicate=MatchAllQueryPredicate}
W/FlutterJNI( 5547): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: com.amazonaws.amplify/datastore_hub_events. Response ID: 51
I/amplify:aws-datastore( 5547): Starting attempt #1
W/amplify:aws-datastore( 5547): Attempt #1 failed.
W/amplify:aws-datastore( 5547): 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.}
W/amplify:aws-datastore( 5547): at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$mutation$4(AppSyncClient.java:352)
W/amplify:aws-datastore( 5547): at com.amplifyframework.datastore.appsync.AppSyncClient$$ExternalSyntheticLambda3.accept(D8$$SyntheticClass:0)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.AppSyncGraphQLOperation.dispatchRequest(AppSyncGraphQLOperation.java:109)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.AppSyncGraphQLOperation.$r8$lambda$s0tPt9Vu7puSi2-I-7S0nxLOkUY(Unknown Source:0)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.AppSyncGraphQLOperation$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
W/amplify:aws-datastore( 5547): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/amplify:aws-datastore( 5547): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/amplify:aws-datastore( 5547): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/amplify:aws-datastore( 5547): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/amplify:aws-datastore( 5547): at java.lang.Thread.run(Thread.java:919)
W/amplify:aws-datastore( 5547): 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.}
W/amplify:aws-datastore( 5547): ... 8 more
W/amplify:aws-datastore( 5547): 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.}
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.auth.ApiRequestDecoratorFactory.forAuthType(ApiRequestDecoratorFactory.java:127)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.auth.ApiRequestDecoratorFactory.fromGraphQLRequest(ApiRequestDecoratorFactory.java:100)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.AppSyncGraphQLOperation.dispatchRequest(AppSyncGraphQLOperation.java:93)
W/amplify:aws-datastore( 5547): ... 7 more
W/amplify:aws-datastore( 5547): Caused by: ApiAuthException{message=No native plugin registered, cause=null, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider.fetchToken(DefaultCognitoUserPoolsAuthProvider.java:81)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider.getLatestAuthToken(DefaultCognitoUserPoolsAuthProvider.java:87)
W/amplify:aws-datastore( 5547): at com.amplifyframework.api.aws.auth.ApiRequestDecoratorFactory.forAuthType(ApiRequestDecoratorFactory.java:125)
W/amplify:aws-datastore( 5547): ... 9 more
I/ViewRootImpl@b518e61[MainActivity]( 5547): MSG_RESIZED: frame=(0,0,1080,2220) ci=(0,72,0,144) vi=(0,72,0,144) or=1
I/ViewRootImpl@b518e61[MainActivity]( 5547): Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)0 dur=5 res=0x1 s={true 540381495296} ch=false
I/amplify:aws-datastore( 5547): Starting attempt #2
Hi @HarkerTech, glad to see the fix was a help. To clarify, you no longer see this exception in these cases, correct?
Hi @ekjotmultani, that is correct. I have removed my previous workaround then tested with "Don't keep activities" enabled and with hot reloads and I no longer see this exception. Thanks!
Hi @olena1911, a fix for this issue was just released for amplify_datastore 2.6.0. Please update your packages and let us know if this resolved your issue!
Hi @HarkerTech, thank you for confirming the fix on your end!
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.