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

Subscription fails to reconnect when app is in background for a long time #396

Closed
chajuss opened this issue Jun 18, 2020 · 17 comments
Closed
Assignees
Labels
bug Something isn't working pending investigation It has been triaged and discussed but the actual work is still pending

Comments

@chajuss
Copy link

chajuss commented Jun 18, 2020

Describe the bug
I have an AWSAppSyncClient subscription to GraphQL via subscribe(subscription:queue:statusChangeHandler:resultHandler).
When going to background, I stop the subscription via AWSAppSyncSubscriptionWatcher.cancel(), and returning to foreground will try to create the subscription from scratch.
This works fine when the app is in background for short periods of time, however after being in the background for a longer period (~10-20 minutes and up), subscription fails to reconnect with "error The operation couldn’t be completed. (AppSyncRealTimeClient.ConnectionProviderError error 3.)"

To Reproduce

  1. Start App and initialise a subscription to GraphQL via subscribe(subscription:queue:statusChangeHandler:resultHandler).

  2. Make sure subscription is connected.

  3. Send app to background and terminate subscription from applicationWillResignActive via AWSAppSyncSubscriptionWatcher.cancel().

  4. Wait a rather long period of time (>10 minutes).

  5. Activate app again and try to create a new subscription from applicationWillEnterForeground.

  6. Subscription tries to reconnect over and over with the following errors:
    2020-06-18 14:42:23.184613+0300 Veev[2875:3089365] [App Delegate] applicationWillEnterForeground(_:) 2020-06-18 14:42:23.186410+0300 Veev[2875:3090878] [AWS AppSync] monitorSubscription(status:): connecting 2020-06-18 14:42:23.251935+0300 Veev[2875:3090874] Connecting to url ... 2020-06-18 14:42:23.352693+0300 Veev[2875:3089690] [] nw_read_request_report [C2] Receive failed with error "Software caused connection abort" 2020-06-18 14:42:23.354298+0300 Veev[2875:3089690] [] nw_read_request_report [C4] Receive failed with error "Software caused connection abort" 2020-06-18 14:42:23.354898+0300 Veev[2875:3089690] [] nw_read_request_report [C3] Receive failed with error "Software caused connection abort" 2020-06-18 14:42:23.832433+0300 Veev[2875:3090881] [Services] onUpdate(): status is Available 2020-06-18 14:42:24.643831+0300 Veev[2875:3089690] WebsocketDidConnect 2020-06-18 14:42:24.644169+0300 Veev[2875:3089690] WebsocketDidConnect, sending init message... 2020-06-18 14:42:24.644804+0300 Veev[2875:3089690] Validating connection 2020-06-18 14:42:24.646696+0300 Veev[2875:3090881] Realtime connection is stale, disconnected. 2020-06-18 14:42:24.660200+0300 Veev[2875:3090881] The operation couldn’t be completed. (AppSyncRealTimeClient.ConnectionProviderError error 3.) 2020-06-18 14:42:24.661796+0300 Veev[2875:3090881] Retrying subscription 8A84E75F-CC65-4E91-9E93-061775CAF56C after milliseconds(217) 2020-06-18 14:42:24.675583+0300 Veev[2875:3090874] Message type does not need signing - connectionInit("connection_init") 2020-06-18 14:42:24.675858+0300 Veev[2875:3090874] Websocket write - {"type":"connection_init"} 2020-06-18 14:42:24.920531+0300 Veev[2875:3090874] Connecting to url ... 2020-06-18 14:42:26.178636+0300 Veev[2875:3090878] WebsocketDidConnect 2020-06-18 14:42:26.178740+0300 Veev[2875:3090878] WebsocketDidConnect, sending init message... 2020-06-18 14:42:26.178851+0300 Veev[2875:3090878] Validating connection 2020-06-18 14:42:26.179641+0300 Veev[2875:3090878] Realtime connection is stale, disconnected. 2020-06-18 14:42:26.180087+0300 Veev[2875:3090878] The operation couldn’t be completed. (AppSyncRealTimeClient.ConnectionProviderError error 3.) 2020-06-18 14:42:26.180223+0300 Veev[2875:3090878] Retrying subscription 8A84E75F-CC65-4E91-9E93-061775CAF56C after milliseconds(481)

Expected behavior
Subscription should reconnect without error.

Environment:

  • AppSync SDK Version: 3.1.2
  • Dependency Manager: Cocoapods
  • Swift Version : 5.0

Device Information:

  • Device: iPhone6+, Simulator
  • iOS Version: iOS 13.4+

Additional context
Trying to restart the subscription after error is received fails with the same behaviour.

@wooj2 wooj2 added the bug Something isn't working label Jun 18, 2020
@sravichandran-gd
Copy link

I am facing the same issue. Do we know which version of sdk this would be fixed? Thank you

@benrosen78
Copy link

Have you been able to find a work around for this?

@palpatim
Copy link
Contributor

@chajuss and @sravichandran-gd @benrosen78

What authorization mode are you each using for your AppSync endpoint?

@chajuss
Copy link
Author

chajuss commented Jul 29, 2020

@palpatim We are using AMAZON_COGNITO_USER_POOLS in our app.

@benrosen78
Copy link

I'm using an API key. I added AppSync by running the amplify add codegen --apiId xxxxxxxx command that is available in the AppSync console.

@sravichandran-gd
Copy link

We use API Key in our app

@palpatim
Copy link
Contributor

Thanks for the updates.

@palpatim
Copy link
Contributor

I believe I've identified the problem and am working on a fix. See aws-amplify/aws-appsync-realtime-client-ios#25 for a work in progress. No ETA on a release, but I'll be working on it tomorrow tomorrow.

@benrosen78
Copy link

Thank you for your promptness. Much appreciated

@sravichandran-gd
Copy link

Thank you @palpatim

@benrosen78
Copy link

Awesome work. Thank you!

@palpatim
Copy link
Contributor

Do note that the release is in process just now, so please wait for 3.1.4 to become available on CocoaPods (which should be in an hour or so, depending on how long the CDN takes to sync up)

@sravichandran-gd
Copy link

Thats awesome. Thank you !!

@palpatim
Copy link
Contributor

Released on 3.1.4.

@howardevans21
Copy link

Thanks! Much appreciated! I have the app scheduled to re-subscribe every few minutes since the subscription may work for a period of time and it works perfectly after re-subscribing. Another way, a user will go off and on the screen to re-subscribe to renew the connection.

The update is a great improvement, but I just wanted to highlight a few issues that may still remain for an enhancement if possible.

Thanks again for all of your help!

@palpatim
Copy link
Contributor

@howardevans21 Could you please open a new issue with details (including repro steps) of the issue you're still seeing? We haven't seen problems such as you describe, so there may be something else going on here.

@howardevans21
Copy link

@palpatim I believe I got the issue resolved when I tested the iOS App.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending investigation It has been triaged and discussed but the actual work is still pending
Projects
None yet
Development

No branches or pull requests

6 participants