awslabs / aws-mobile-appsync-sdk-android

Android SDK for AWS AppSync.
https://docs.amplify.aws/sdk/api/graphql/q/platform/android/
Apache License 2.0
105 stars 58 forks source link

AppSyncOfflineMutationManager seems to block Main Thread on fresh installation of App #350

Closed Lavanya2204-developer closed 1 year ago

Lavanya2204-developer commented 3 years ago

I tried using the latest SDK to implement App Sync but see below logs repeatedly when I run the application. These logs continuously print when the app is freshly installed and seem to block the UI thread as we see a black screen on the activity on which we are subscribing to events. There is no issue on subsequent launch.

V/QueueUpdateHandler: Thread:[13931]: Got message to take action on the mutation queue.
    Thread:[13931]: Got message to process next mutation if one exists.
V/AppSyncOfflineMutationManager: Thread:[13931]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
    Thread:[13931]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
V/AppSyncOfflineMutationInterceptor: Thread:[13931]: processing Mutations
V/QueueUpdateHandler: Thread:[13931]: Got message to take action on the mutation queue.
    Thread:[13931]: Got message to process next mutation if one exists.
V/AppSyncOfflineMutationManager: Thread:[13931]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
    Thread:[13931]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
V/AppSyncOfflineMutationInterceptor: Thread:[13931]: processing Mutations
V/QueueUpdateHandler: Thread:[13931]: Got message to take action on the mutation queue.
    Thread:[13931]: Got message to process next mutation if one exists.

Environment:

Device Information:

Additional context FYI, I am trying to subscribe to the App sync client inside CoroutineScope(Dispatchers.IO). We are using Amazon Cognito UserPools (AMAZON_COGNITO_USER_POOLS) as the Authentication mode

iamfirdous8 commented 2 years ago

Any update on this? I am facing exact same issue.

div5yesh commented 2 years ago

Can you please share code snippets and configuration json file with sensitive information removed?

iamfirdous8 commented 2 years ago

Hi @div5yesh

This is how we initialize the appsync client,

val awsConfig = AWSConfiguration(getJSONObject())

val regions = Regions.fromName(BuildConfig.AWS_REGION)
val cognitoUserPool = CognitoUserPool(mContext.applicationContext, awsConfig)
val basicCognitoUserPoolsAuthProvider = BasicCognitoUserPoolsAuthProvider(cognitoUserPool)
mClient = AWSAppSyncClient.builder()
        .context(mContext.applicationContext)
        .awsConfiguration(awsConfig)
        .cognitoUserPoolsAuthProvider(basicCognitoUserPoolsAuthProvider)
        .s3ObjectManager(S3ObjectManagerImplementation(AmazonS3Client(AWSMobileClient.getInstance(), Region.getRegion(regions))))
        .build()

And here's how we get the JSONObject

private fun getJSONObject(): JSONObject {
    val jsonObject = JSONObject()

    // CognitoUserPool
    val default = JSONObject()
    default.apply {
        put("PoolId", mAwsConfig.appSyncConfig?.poolId)
        put("AppClientId", mAwsConfig.appSyncConfig?.clientId)
        put("Region", BuildConfig.AWS_REGION)
    }
    val cognitoUserPool = JSONObject()
    cognitoUserPool.put("Default", default)
    jsonObject.put("CognitoUserPool", cognitoUserPool)

    // AppSync
    val appSyncDefault = JSONObject()
    appSyncDefault.apply {
        put("ApiUrl", mAwsConfig.appSyncConfig?.apiUrl)
        put("Region", BuildConfig.AWS_REGION)
        put("AuthMode", "AMAZON_COGNITO_USER_POOLS")
    }
    val appSync = JSONObject()
    appSync.put("Default", appSyncDefault)
    jsonObject.put("AppSync", appSync)

    return jsonObject
}
iamfirdous8 commented 2 years ago

Any update?

iamfirdous8 commented 2 years ago

@div5yesh Any update on this issue?

poojamat commented 2 years ago

@iamfirdous8 are you initializing appsync sdk in the application class?

iamfirdous8 commented 2 years ago

Yes @poojamat, It's being initialized in the Application class.

poojamat commented 2 years ago

@Lavanya2204-developer the log you have provided suggests that mutation queue is dealt with in a background thread what makes you believe its blocking the main thread?