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

Freeze on offline WiFi with Selective Sync: Query and Save calls get stuck in await #5662

Open
2 of 14 tasks
giulitu95 opened this issue Nov 12, 2024 · 7 comments
Open
2 of 14 tasks
Assignees
Labels
Android Issues specific to the Android Platform bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category

Comments

@giulitu95
Copy link

Description

This problem occurs on Android platforms when the device is connected to a wify network without internet connection.
If a selective sync is configured and data are cyclically saved on the datastore, eventually, the execution gets stuck in the save method. My configuration includes Datastore, Api and Auth plugins.

Categories

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

Steps to Reproduce

  1. Start the app with internet connection
  2. Initialize amplify
  3. Sign-up and Sign-in with Cognito authentication
  4. Switch the device to a wify without internet connection
  5. Cyclically call the method await Amplify.Datastore.save(model)
  6. Eventually, the execution gets stuck in an await

Screenshots

No response

Platforms

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

Flutter Version

3.24.4

Amplify Flutter Version

2.5.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 Nov 12, 2024
@Equartey Equartey added Android Issues specific to the Android Platform to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided datastore Issues related to the DataStore Category labels Nov 12, 2024
@Equartey
Copy link
Contributor

Hi @giulitu95, thanks for taking the time to open this issue. We will investigate this issue and provide an update when we can.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Nov 12, 2024
@ekjotmultani
Copy link
Member

Hello @giulitu95, I've been unable to reproduce this issue. Are you using a physical device to get this issue? Also, are the cyclical calls to save being made programmatically or by repeated user input?

@giulitu95
Copy link
Author

giulitu95 commented Nov 19, 2024

Hi @ekjotmultani, I'm using a physical device (Samsung Galaxy S22). I have been able to reproduce the problem on a simple app calling the Amplify.DataStore.save() method in an infinite loop programmatically.

final mv = MachineVersion(machineSerialNumber: 23);
while (true) {
  print("-- Saving");
  try {
    await Amplify.DataStore.save(mv);
  } catch (e) {
    print("-- Error: $e");
  }
  print("-- Saved");;
}

After some cycles, the program gets stucks printing as last message "--Saving" and the execution never enters in the catch block. This occurs only when the device has not internet connection but is connected to a local WiFi network (without internet connection).
The following is my amplify configuration:

final auth = AmplifyAuthCognito();
final api = AmplifyAPI();
final datastore = AmplifyDataStore(
    modelProvider: ModelProvider.instance,
    options: DataStorePluginOptions(syncExpressions: [
      DataStoreSyncExpression(
          MachineVersion.classType, () => MachineVersion.ID.eq("test")),
    ]));
await Amplify.addPlugins([datastore, api, auth]);
await Amplify.configure(amplifyconfig);

If I do not specify a DataStoreSyncExpression (removing the entire options attribute), the execution does not stuck.

This is the graphQl for the model used as example (but it happens with any models defined in my graphQl):

[...]
type MachineVersion @model @auth(
        rules: [
            { allow: groups, groups: ["Admins"], operations: [create, read, update, delete]}
            { allow: owner }
        ]
    ){
    id: ID! @primaryKey
    machineSerialNumber: Int!
    remoteSoftwareUpdateDate: String
    workingData: [WorkingData] @hasMany(fields: ["id"])
    diagnosisSession: [DiagnosisSession] @hasMany(fields: ["id"])
    machineComponent: [MachineComponent] @hasMany(fields: ["id"])
    owner: String @auth(
        rules: [
            { allow: groups, groups: ["Admins"], operations: [create, read, update, delete]}
            { allow: owner, operations: [read, delete] }
        ]
    )
}
[...]

Note also that whenever Amplify tries to save the model (before it gets stuck), the debug console shows many exceptions as:

E/amplify:aws-datastore( 4591): Failure encountered while attempting to start API sync.
E/amplify:aws-datastore( 4591): DataStoreException{message=DataStore subscriptionProcessor failed to start., cause=DataStoreException{message=Error during subscription., cause=ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}, recoverySuggestion=Evaluate details.}, recoverySuggestion=Check your internet.}
E/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$4$com-amplifyframework-datastore-syncengine-Orchestrator(Orchestrator.java:344)
E/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.syncengine.Orchestrator$$ExternalSyntheticLambda8.subscribe(Unknown Source:2)
[...]
E/amplify:aws-datastore( 4591): Caused by: DataStoreException{message=Error during subscription., cause=ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}, recoverySuggestion=Evaluate details.}
E/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$2(AppSyncClient.java:322)
E/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.appsync.AppSyncClient$$ExternalSyntheticLambda5.accept(Unknown Source:4)
[...]
E/amplify:aws-datastore( 4591): Caused by: ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}
E/amplify:aws-datastore( 4591): 	at com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(SubscriptionEndpoint.java:152)
E/amplify:aws-datastore( 4591): 	... 7 more

[...]

W/amplify:aws-datastore( 4591): API sync failed - transitioning to LOCAL_ONLY.
W/amplify:aws-datastore( 4591): DataStoreException{message=Error during subscription., cause=ApiException{message=Thread interrupted waiting for connection acknowledgement, cause=null, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}, recoverySuggestion=Evaluate details.}
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$2(AppSyncClient.java:322)
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.appsync.AppSyncClient$$ExternalSyntheticLambda5.accept(Unknown Source:4)
[...]
W/amplify:aws-datastore( 4591): Caused by: ApiException{message=Thread interrupted waiting for connection acknowledgement, cause=null, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(SubscriptionEndpoint.java:152)
W/amplify:aws-datastore( 4591): 	... 7 more

[...]

W/amplify:aws-datastore( 4591): DataStore failed to start after emitter was disposed.
W/amplify:aws-datastore( 4591): DataStoreException{message=Subscription operations were interrupted during setup., cause=null, recoverySuggestion=Retry}
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.syncengine.SubscriptionProcessor.startSubscriptions(SubscriptionProcessor.java:155)
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$4$com-amplifyframework-datastore-syncengine-Orchestrator(Orchestrator.java:342)

[...]

W/amplify:aws-datastore( 4591): DataStoreException{message=Error during subscription., cause=ApiException{message=Interrupted waiting for Cognito Userpools token., cause=java.lang.InterruptedException, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}, recoverySuggestion=Evaluate details.}
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$2(AppSyncClient.java:322)
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.datastore.appsync.AppSyncClient$$ExternalSyntheticLambda5.accept(Unknown Source:4)
[...]
W/amplify:aws-datastore( 4591): Caused by: ApiException{message=Interrupted waiting for Cognito Userpools token., cause=java.lang.InterruptedException, recoverySuggestion=Sorry, we don’t have a recovery suggestion for this error.}
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider.fetchToken(DefaultCognitoUserPoolsAuthProvider.java:73)
W/amplify:aws-datastore( 4591): 	at com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider.getLatestAuthToken(DefaultCognitoUserPoolsAuthProvider.java:87)
[...]
W/amplify:aws-datastore( 4591): Caused by: java.lang.InterruptedException
W/amplify:aws-datastore( 4591): 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1048)
W/amplify:aws-datastore( 4591): 	at java.util.concurrent.Semaphore.acquire(Semaphore.java:318)

Also other exception occurs, let me know if you need the entire detailed debug log

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Nov 19, 2024
@NikaHsn
Copy link
Member

NikaHsn commented Nov 19, 2024

@giulitu95 thank you for providing these details. we will look into this issue and get back to you with any updates.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Nov 19, 2024
@giulitu95
Copy link
Author

Thank you @NikaHsn. I forgot to mention that the problem is not related only to the save method, but if I alternate save with query methods the execution could get stuck also in the query future.

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Nov 20, 2024
@NikaHsn
Copy link
Member

NikaHsn commented Nov 20, 2024

@giulitu95 thanks for providing more details on this. we will look into this issue and provide update as we have them.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Nov 20, 2024
@ekjotmultani
Copy link
Member

@giulitu95 thanks again for the added information! I have been successful in reproducing this issue and we will track it as a bug. I also noticed the massive amounts of other exceptions in the output so we'll investigate that too

@ekjotmultani ekjotmultani added the bug Something is not working; the issue has reproducible steps and has been reproduced label Nov 20, 2024
@github-actions github-actions bot removed the pending-triage This issue is in the backlog of issues to triage label Nov 20, 2024
@ekjotmultani ekjotmultani removed the to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues specific to the Android Platform bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category
Projects
None yet
Development

No branches or pull requests

4 participants