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

AppSync subscription connections are dropping with no feedback #1213

Closed
JLau-cy opened this issue Feb 6, 2019 · 8 comments
Closed

AppSync subscription connections are dropping with no feedback #1213

JLau-cy opened this issue Feb 6, 2019 · 8 comments
Assignees
Labels
appsync Issues related to AppSync duplicate This issue or pull request already exists

Comments

@JLau-cy
Copy link

JLau-cy commented Feb 6, 2019

Describe the bug
I am noticing that internally AppSync is dropping the web socket connection at random times with unknown reasons and are not reported back to the app. This is problematic as there is no callback for when this happens or when it connects for that matter.

As there is no feedback to web socket connection states from AppSync I cannot detect these connection drops. Other than relaunching the app or going in and out of a screen to trigger my code for subscription, there is no way to know when reestablish the connection based on these events.

Whenever a connection drops, I notice an error in the console (MQTT session error, code: 2). However there is no mention of the cause or ways to recover.

As these connection drops are happening randomly there is no defined way to reproduce. However I notice it the most when:

  1. Initiate a subscription in a ViewController.
  2. Have a long lived object outside of the ViewController to hold the returned AWSAppSyncSubscriptionWatcher object.
  3. Navigate to another ViewController
  4. Initiate another subscription

Sometimes between 3 and 4 or sometime after 4 I will notice MQTT session error, code: 2 in the console and if I navigate back to the first ViewController, I will no longer be receiving real time data.

If I do not navigate away from a view controller after establishing a connection I do not see a connection drop.

A thing to note is that I do not call cancel() anywhere in my code to terminate the subscription myself, so I am not sure what is causing the terminations.

In addition to this, every time it connects/ disconnects it take a considerable amount of time to do so (2-3 seconds). If during these times I make a Query or Mutation then it will most likely timeout, is this expected behaviour?

Which AWS service(s) are affected?
AWSAppSync iOS SDK

Expected behavior
I am expecting the ability to have a long lived object (singleton) to hold a number of AWSAppSyncSubscriptionWatcher objects such that no matter what ViewController I am on, my model objects can still be populated by real-time data.

I am also expecting ways to react to subscription lifecycle events (connected, disconnected, retry)

Environment(please complete the following information):

  • SDK Version: AWSAppSync 2.9.1
  • Dependency Manager: Cocoapods
  • Swift Version : 4.2

Device Information (please complete the following information):

  • Device: iPhone and simulator
  • iOS Version: 12.0+
@rohandubal
Copy link
Contributor

Hello @JLau-cy

Sorry that you are having issues using the SDK. Could you please help answer these couple questions so that I can better investigate the issue?

  • Do you see of data only for the older connections or for ALL the connections?
  • The long lived object which you have has a strong reference to the watcher correct?
  • Is the network wifi or cellular?

Thanks,
Rohan

@rohandubal rohandubal added pending-community-response Issue is pending response from the issue requestor appsync Issues related to AppSync labels Feb 6, 2019
@JLau-cy
Copy link
Author

JLau-cy commented Feb 6, 2019

@rohandubal Please find answers below:

  • Do you see of data only for the older connections or for ALL the connections?
    Whenever I see the connection drop I normally lose the old data. However when the connection drops it typically takes 2-3 seconds before I can make a successful Query or Mutation. If I happen to trigger a Query or Mutation during that time I normally see a timeout error for those requests.

  • The long lived object which you have has a strong reference to the watcher correct?
    This is correct, I have a singleton with a strong reference to the watcher.

  • Is the network wifi or cellular?
    Wifi

My workaround so far is to re-subscribe every time I land on a view controller that expects a subscription to ensure I have a live subscription. However this is not a scalable solution as there is a 2-3 seconds overhead to establish a new subscription and there are no connection state callbacks which means it is all guess work as to when a connection has been established or dropped.

@rohandubal rohandubal added investigating This issue is being investigated and removed pending-community-response Issue is pending response from the issue requestor labels Feb 7, 2019
@rohandubal
Copy link
Contributor

Thanks for the feedback @JLau-cy

I will try to reproduce this issue on my side.

@rohandubal
Copy link
Contributor

Hello @JLau-cy I wrote a quick update to our sample using our Events starter sample which demonstrates how to do multiple long lived subs. You can apply the diff on the Github sample to check the changes. Please find the sample attached.
SampleWithSubs.zip

@rohandubal rohandubal added pending-community-response Issue is pending response from the issue requestor and removed investigating This issue is being investigated labels Feb 11, 2019
@JLau-cy
Copy link
Author

JLau-cy commented Feb 24, 2019

@rohandubal Thank you.

I am still having trouble at monitoring the MQTT connection status. Is it possible to add a connectionState property to AWSAppSyncSubscriptionWatcher that is updated when connectedCallbackDelegate or disconnectCallbackDelegate is called?

Without the above, it is not possible to know for certain when a connection state changes.

The scenario that I am trying to solve is:

  1. Subscribe to topic
  2. Initiate an API operation only when I know a subscription connection has been established
  3. Wait for messages to be sent to topic.

The issue is if I perform 2 without knowing for certain subscription connection is active, there is a chance that I will miss a message sent to the topic. Some of the messages are unique and can only be sent once, hence missing these messages will cause issues in the app flow.

@frankmuellr frankmuellr removed the pending-community-response Issue is pending response from the issue requestor label Feb 25, 2019
@minbi minbi added the duplicate This issue or pull request already exists label Mar 7, 2019
@palpatim
Copy link
Member

palpatim commented Mar 7, 2019

Hi @JLau-cy

We are exposing a watcher status as part of awslabs/aws-mobile-appsync-sdk-ios#42

This feature is specifically intended to allow you to solve the "query/mutate only after subscription is active" use case: once the status is updated to .connected, the subscription has received an acknowledgement from the service and is ready to receive updates.

@palpatim palpatim added work in progress Issues was triaged and investigation done Reviewing and removed work in progress Issues was triaged and investigation done labels Mar 8, 2019
@svsharsha
Copy link

Hi @rohandubal ,

Even I'm also facing this issue.
In my debugging after some point of time the connection is loosing between APPSYNC and our mobile application.

"Subscription Terminated" is displayed in logs.Its trying to re-establish connection but its not happening.

Please fix this issue.

@palpatim
Copy link
Member

Sorry for missing the update on this issue, but we believe this was fixed by iOS AppSync PR 196, and refined by @rohandubal on subsequent commits. If you see other issues, please open an issue in the iOS AppSync repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appsync Issues related to AppSync duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants