Closed vgribok closed 11 months ago
Hi @vgribok with what operation on the model would trigger this exception for you?
Hi @vgribok with what operation on the model would trigger this exception for you?
I was running an observed query for a different model:
StreamProvider<List<T>>((ref) {
final Stream<QuerySnapshot<T>> snapshotStream = Amplify.DataStore.observeQuery(
SomeOtherModelType, where: where, sortBy: sortBy, throttleOptions: throttleOptions
);
return snapshotStream.map((snapshot) => snapshot.items);
})
@HuiSF I went on a wild goose chase trying to come up with more data for this issue. Here are the findings.
I upgraded to "1.0.0-next.3".
I changed the schema so that the models would have id
fields for ownerId:
type UserProfile @model
@auth(rules: [
{ allow: groups, groups: ["GsAdmins"] } # Unrestricted access to members of the "admin" user pool group
{ allow: owner, ownerField: "id" }
])
{
id: String! @primaryKey
firstName: String
lastName: String!
}
That required to run amplify api remove
because not even amplify api rebuild --allow-destructive-graphql-schema-updates
could deal with the change. Then I restored project changes by doing git revert followed by amplify init
and amplify api push
. Not a smooth experience, but I got through it.
After I regenerated the models and ran the app, on iOS it was still running fine - the sync back and forth, but on Android the sync is broken seemingly in more ways than one. This time the inability to sync was due to an authorization issue of some kind, which is not observed on iOS with exacly the same flow of logging in and out with Cogntio AutheticatedView:
W/amplify:aws-datastore(15348): API sync failed - transitioning to LOCAL_ONLY.
W/amplify:aws-datastore(15348): DataStoreException{message=Initial sync during DataStore initialization failed., cause=io.reactivex.rxjava3.exceptions.CompositeException: 2 exceptions occurred. , recoverySuggestion=There is a possibility that there is a bug if this error persists. Please take a look at
W/amplify:aws-datastore(15348): https://github.com/aws-amplify/amplify-android/issues to see if there are any existing issues that
W/amplify:aws-datastore(15348): match your scenario, and file an issue with the details of the bug if there isn't.}
W/amplify:aws-datastore(15348): at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$3$Orchestrator(Orchestrator.java:324)
W/amplify:aws-datastore(15348): at com.amplifyframework.datastore.syncengine.-$$Lambda$Orchestrator$PVk58tU0K8ndPJYnH_tRmf4RGwE.subscribe(Unknown Source:2)
W/amplify:aws-datastore(15348):
...
W/amplify:aws-datastore(15348): Caused by: io.reactivex.rxjava3.exceptions.CompositeException$ExceptionOverview: Multiple exceptions (2)
W/amplify:aws-datastore(15348): |-- com.amplifyframework.datastore.DataStoreException: Failure performing sync query to AppSync: [GraphQLResponse.Error{message='Not Authorized to access syncDestinations on type ModelDestinationConnection', locations='[GraphQLLocation{line='2', column='3'}]', path='[GraphQLPathSegment{value='syncDestinations'}]', extensions='{errorInfo=null, data=null, errorType=Unauthorized}'}]
W/amplify:aws-datastore(15348): at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$sync$0(AppSyncClient.java:116)
W/amplify:aws-datastore(15348): |-- java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: RxCachedThreadScheduler-151
W/amplify:aws-datastore(15348): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1415)
I/amplify:aws-datastore(15348): Orchestrator transitioning from SYNC_VIA_API to LOCAL_ONLY
I/amplify:aws-datastore(15348): Setting currentState to LOCAL_ONLY
I/amplify:aws-datastore(15348): Stopping subscription processor.
But what was really surprising that after reporting all of the above, it actually down-synced a few records from the cloud:
I/amplify:aws-datastore(15348): Setting currentState to LOCAL_ONLY
I/amplify:aws-datastore(15348): Stopping subscription processor.
I/amplify:aws-datastore(15348): Stopped subscription processor.
W/tstride.logbook(15348): Long monitor contention with owner pool-4-thread-169 (17061) at void com.amplifyframework.api.aws.SubscriptionEndpoint.releaseSubscription(java.lang.String)(SubscriptionEndpoint.java:291) waiters=5 in void
... lots of these noisy log records removed ^^ ....
com.amplifyframework.api.aws.SubscriptionEndpoint.releaseSubscription(java.lang.String) for 1.584s
D/EGL_emulation(15348): app_time_stats: avg=575.16ms min=1.41ms max=10531.65ms count=19
I/flutter (15348): DataStore query returned 2 items of type UserCertification
After I uninstalled the app on Android (emulator) and ran it again, I could no longer downsync anything - the sync remains dead. (Update: down-sync works sometimes, it's not fully dead like up-sync.)
To summarize, Android does not up-sync because of an authorization issue that iOS does not have, and despite of the Auth issue, it down-syncs sometimes.
The root cause is that DataStore sync fails when encountering models for which the current user is unauthorized. I am not sure why this is an Andoird-only failure, though. It should either fail on all platforms, or succeed on all platforms. Also, if a user is unauthorized for a model, the sync should just skip syncing the model, not switch to the local only mode.
@vgribok - This issue fell off our radar. Apologies about that.
I would like to try to reproduce this to see if it is still an issue, but want to confirm that I have the correct reproduction steps.
Can you confirm these reproduction steps are correct?
type UserProfile @model
@auth(rules: [
{ allow: groups, groups: ["GsAdmins"] } # Unrestricted access to members of the "admin" user pool group
{ allow: owner, ownerField: "id" }
])
{
id: String! @primaryKey
firstName: String
lastName: String!
}
@vgribok - Let us know if you recall the reproduction steps for this issue. Otherwise we will close this one out. Thanks.
@Jordan-Nelson, yes the steps are correct. Please note that on iOS there was not problem, and the failure occurred only on Android.
@vgribok I am unable to reproduce this. Below are the steps I took and the app/schema that I used. If you are able to reproduce this with the latest version of Amplify, please let me know.
Steps:
Schema:
App:
Closing due to inactivity.
Description
It's likely to be an Android platform specific issues, but as I have little knowledge of that and encountered the problem in Flutter, filling it here. Please feel free to move.
Here's the model:
The CLI didn't complain about the schema and it syncs fine on iOS but sync fails on Android with
Ran it against Android API 31 and 33 with same outcome.
Feel free to DM me for the full stack trace and/or .graphql schema.
Categories
Steps to Reproduce
No response
Screenshots
No response
Platforms
Android Device/Emulator API Level
API 31
Environment
Dependencies
Device
Android Emulator of Pixel 3a on MacOS M1
OS
Android 33
Deployment Method
Amplify CLI
CLI Version
10.6.1
Additional Context
No response
Amplify Config
Instructions unclear