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

fix-376/Add checks to prevent re-initialization of the connectivitywatcher #387

Closed gpanshu closed 2 years ago

gpanshu commented 2 years ago

Add checks to prevent re-initialization of the connectivityWatcher and unregistering before registering the same watcher to prevent too manyrequests to networkcallback registeration

*Issue #376

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

tbartley commented 1 year ago

Not sure how the change in aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AppSyncOfflineMutationManager.java is intended to work. Since it's in the constructor, this.connectivityWatcher will always be null and so the unregister will never be called.

We see this issue more in our testing where we have a lot of instances of this class each of which has registered a watcher and so we hit the limit when we have a certain number of tests. It would be very useful to have a method on AWSAppSyncClient that would call down in to AppSyncOfflineMutationManager to unregister the callback. We could then call this on test teardown.