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 - Initial cloud sync failed #4012

Closed
5 of 14 tasks
adplant opened this issue Oct 25, 2023 · 7 comments
Closed
5 of 14 tasks

Datastore - Initial cloud sync failed #4012

adplant opened this issue Oct 25, 2023 · 7 comments
Assignees
Labels
datastore Issues related to the DataStore Category pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.

Comments

@adplant
Copy link

adplant commented Oct 25, 2023

Description

When I log in to my app the initial sync happens, and it's fairly reliable. Definitely not perfect, but works more than it doesn't first time around.

However, when I stay signed in and just close the app (I'm on Android and swipe away the app so it's not in the background anymore either) something seems to happen b/c when I open the app again and the sync
initiates, but it very frequently gives me this message (see attached).

AppSyncError.txt

What's really a pain point is that I can't seem to handle the error that is thrown from the datastore:

W/amplify:aws-datastore(32223): IrRecoverableException{message=Empty response from AppSync., cause=null, recoverySuggestion=Report to AWS team.}
W/amplify:aws-datastore(32223): 	at com.amplifyframework.datastore.syncengine.SyncProcessor.lambda$syncPage$16(SyncProcessor.java:325)
W/amplify:aws-datastore(32223): 	at com.amplifyframework.datastore.syncengine.SyncProcessor$$ExternalSyntheticLambda11.accept(Unknown Source:4)
W/amplify:aws-datastore(32223): 	at com.amplifyframework.datastore.appsync.AppSyncClient$$ExternalSyntheticLambda4.accept(Unknown Source:4)
W/amplify:aws-datastore(32223): 	at com.amplifyframework.api.aws.MultiAuthAppSyncGraphQLOperation$OkHttpCallback.onResponse(MultiAuthAppSyncGraphQLOperation.java:183)
W/amplify:aws-datastore(32223): 	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:539)
W/amplify:aws-datastore(32223): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
W/amplify:aws-datastore(32223): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
W/amplify:aws-datastore(32223): 	at java.lang.Thread.run(Thread.java:1012)
E/amplify:flutter:datastore(32223): DataStoreException{message=Initial cloud sync failed for MyModel8., cause=IrRecoverableException{message=Empty response from AppSync., cause=null, recoverySuggestion=Report to AWS team.}, recoverySuggestion=Check your internet connection.}
E/amplify:aws-datastore(32223): Failure encountered while attempting to start API sync.

Categories

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

Steps to Reproduce

  1. Open app
  2. Log in
  3. Let initial sync happen
  4. Operate inside the app (works fine)
  5. Close the app (swipe/dismiss it from the background to completely close...note, you do not log out)
  6. Open the app again and see the sync error attached (app never completes sync)

Screenshots

No response

Platforms

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

Flutter Version

3.13.8

Amplify Flutter Version

1.4.1

Deployment Method

Amplify CLI

Schema

If needed I can send privately
@suryaishnavi
Copy link

Greetings! I am working on Cashflow, a fintech app built with Flutter and AWS Amplify. It enables collection agents to create customers, manage loan transactions, and collect EMI payments from borrowers in their assigned areas.

The issue at hand specifically arises in release mode on Android, and the device remains consistently connected to the network.

Once the release APK is installed, all CRUD (Create, Read, Update, Delete) operations performed should automatically sync data to the cloud. However, if the app is left unused for an extended period or resumes from a detached lifecycle state, syncing issues may occur. For instance, if the app is swiped away, the phone is turned off and on again, and the app is reopened, the data gets stuck in the "Outbox Mutation Enqueued" state, failing to sync with the cloud. To sync local mutations to the cloud, a restart of the app is always required

I've attempted various solutions, such as stopping and restarting the Amplify DataStore and reinitializing the plugin at runtime, but the issue persists.

Upon my careful observation, I have come to the conclusion that my issue is related to the utilization of a GraphQL schema. Every time data syncing halts just before the "Outbox Mutation Processed" state, It indicates the problem arises when the datastore is interacting with the GraphQL API for data synchronization (resulting in a cessation of cloud syncing due to GraphQL API issues).

I noticed that if my mobile device is disconnected from the network, any new customers I create, let's say A and B, are saved locally. When I'm connected to the network again, if there's an error with the GraphQL API, the data for customers A and B doesn't sync with the cloud (I used the DataStore errorHandler parameter to detect errors, but I did not receive any errors from the errorHandler function. Each time, the data stops at outboxMutationEnqueuedEvent). Although I didn't receive any plugin errors, Later, I created two more customers, C and D, and their data is also saved locally. However, after restarting the app, only customers A and B's data is synced, but not customers C and D's (which means that the data created before the plug-in error is retained and synced to the cloud, but the data created after the plug-in error is only retained locally and isn't synced to the cloud) If I reinstall the app, I lose the data for customers C and D.

I would greatly appreciate any recommendations or specific steps to address this issue. If you have encountered a similar challenge or have insights that could guide me, please feel free to share. Any additional information you believe would be helpful in resolving this issue is more than welcome.

Thank you for your time and assistance in advance! Your guidance is highly valued.

@cwomack cwomack added datastore Issues related to the DataStore Category pending-triage This issue is in the backlog of issues to triage labels Oct 27, 2023
@adplant
Copy link
Author

adplant commented Nov 1, 2023

@cwomack Any update to this? I'm currently just trying to do a workaround where I can signout if I get that final error message:
I/amplify:aws-api(32223): No more active subscriptions. Closing web socket.

But I'm not even having success doing that. I tried setting up an ApiHubEvent listener but I never get anything from it:

 void listenToApiHub() {
    safePrint('<listenToApiHub> Start...');

    apiHubSubscription =
        Amplify.Hub.listen<ApiHubEventPayload, HubEvent<ApiHubEventPayload>>(
            HubChannel.Api, (event) {
      safePrint('<listenToApiHub> ApiHubEvent: ${event.eventName}');
// Enter logic to signout if the event.eventName message == No more active subscriptions. Closing web socket.
    });
    _listeningToApiHub = true;
  }

  void stopListeningToApiHub() {
    apiHubSubscription.cancel();
    setState(() {
      _listeningToApiHub = false;
    });
    safePrint('<stopListeningToApiHub> Listening to hub? $_listeningToHub');
  }

Any suggestions for any way to fix this or do a workaround to at least sign out when the sync doesn't progress? I really need this to get fixed asap. Thanks!

@adplant adplant changed the title AppSync not reliable Datastore - Initial cloud sync failed Nov 1, 2023
@adplant
Copy link
Author

adplant commented Nov 1, 2023

@cwomack I updated the initial problem statement to include my issue of not being able to handle the error. I would really appreciate a response soon. This is definitely a pain point in our project.

@adplant
Copy link
Author

adplant commented Nov 1, 2023

Looks like this issue is basically the exact same -> #3658 and this issue provides the solution -> aws-amplify/amplify-category-api#1853

However, I would still like to know how to handle that error if I was to see it again in the future (or something like it).

@khatruong2009 khatruong2009 self-assigned this Nov 2, 2023
@khatruong2009
Copy link
Member

Hi @adplant. Just to confirm, did the solution provided in this end up resolving your issue?

@adplant
Copy link
Author

adplant commented Nov 2, 2023

@khatruong2009 Yes, that solved the sync issue. I would still like to know how to catch that error if I ever see it again though (before closing this ticket).

@khatruong2009
Copy link
Member

Hi @adplant, I would suggest putting a try catch block around the problematic code (probably Datastore.start() or trying to save a model) if you run into anymore issues.

@khatruong2009 khatruong2009 added pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. and removed pending-triage This issue is in the backlog of issues to triage labels Nov 28, 2023
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 pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants