Closed shashika-v closed 2 years ago
@shashika-v .Thank you for opening this issue. Could you give us a sample code of how you are using this in your App?
Hi @shashika-v You should be able to get the timeout message and use check for the error message. You can use the error callback from the subscription (observer) to respond to the timeout appropriately.
@vyomr13 - As quoted earlier, we are getting the callback for error and based on that, we are removing all the subscriptions and after 10 seconds of that, trying to re-establish the connection. But our issue is we aren't getting any callback/promise after unsubscribing is successful or connection is lost. You can read through the entire description and the expected behaviour too.
@shashika-v This sounds more like a feature request than a bug, so I'm going to label it as such. Can you provide an example of what that functionality might look like for you ideally?
EDIT: I've added this issue to a feature request we're going to use for tracking issues related to subscriptions and WebSockets to consolidate them and see where we can focus our efforts to improve developer experience.
I came across this in the docs for error handling (relevant code snippet below): https://docs.amplify.aws/lib/graphqlapi/offline/q/platform/js/#error-handling
I'm not using AWSAppSyncClient
to initialize the client, Amplify is handling that, but it looks like being able to access offlineConfig/callback
would resolve this issue.
Is there a way to do that currently via Amplify or would I need to rewire things so that I initialize the client directly?
const client = new AWSAppSyncClient({
url: awsconfig.aws_appsync_graphqlEndpoint,
region: awsconfig.aws_appsync_region,
auth: {
type: AUTH_TYPE.API_KEY,
apiKey: awsconfig.aws_appsync_apiKey,
},
offlineConfig: {
callback: (err, succ) => {
if(err) {
const { mutation, variables } = err;
console.warn(`ERROR for ${mutation}`, err);
} else {
const { mutation, variables } = succ;
console.info(`SUCCESS for ${mutation}`, succ);
}
},
},
});
@Jordan-Eckowitz This is not exposed through Amplify's API library so you would have to use the AppSync client manually. We are currently working on improving handling for socket connection status in Amplify. You can track the work the team is doing on this PR: https://github.com/aws-amplify/amplify-js/pull/10063
@shashika-v @Jordan-Eckowitz We recently implemented some improvements to our subscriptions. Please upgrade to the latest version of aws-amplify
and let us know if you are still experiencing this issue.
@shashika-v @Jordan-Eckowitz We recently implemented some improvements to our subscriptions. Please upgrade to the latest version of
aws-amplify
and let us know if you are still experiencing this issue.
Thanks @chrisbonifacio, I upgraded a few weeks back and all seems to be working now!
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
Describe the bug
This is an issue with the subscription socket connection with the Amplify SDK. The issue happens on iOS build when the app goes to the inactive state and resume back it throws out an error message "AWSAppSyncRealTimeProvider - Disconnect error: Timeout disconnect". This happens in android when there is very long duration of inactivity.
When we tried multiple implementation setup including unsubscribing from all the subscriptions on the error to disconnecting the socket and tried resubscribing, which still throws out the error.
Currently, after unsubscribing, giving a timeout of 10 seconds to reestablish the connection works but again that is just a work-around which can fail on network issues etc. We need to exactly know when the connection is disconnected or at least when the unsubscribing is successful. There is no callback/promise for either unsubscribing or when connection ends.
Expected behavior
Callback present or promise returned on unsubscribing or when socket connection ends.
Reproduction steps
Install the package aws-amplify
Configure it to connect to GraphQL endpoints.
We are following the pattern for subscribing/unsubscribing as per official Amplify documentation( API and graphqlOperation are imported from "aws-amplify" package
After unsubscribing, there is no promise/callback. Also, we are unsubscribing from all subscriptions to end the connection. But again, there is no way to get notified/callback when the connection ends currently.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
const appSyncConfig = { aws_appsync_graphqlEndpoint: ***, aws_appsync_region: ****, aws_appsync_authenticationType: ****, }; Amplify.configure(appSyncConfig);
Additional configuration
No response
Mobile Device
All iOS for less time of inactivity and android for longer time of inactivity
Mobile Operating System
iOS 15, Android 10
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response