amplify-js: Appsync graphQL connection closed error
Hi I am using subscription via graphQL and getting frequent connection closed error from Appsync, for no apparent reason. It seems to happen at random times. Don’t know how to reproduce it.
My .js code:
subscribeExhibitorNotifications = async() => { try { this.exhitorStatusSubscription = await API.graphql(graphqlOperation(onCreateOveceventsExhibitorStatus)); if (this.exhitorStatusSubscription) { this.exhitorStatusSubscription.subscribe({ next: (event) => { … } else { … } }, error: error => { console.log("error in graphQL onCreateOveceventsExhibitorStatus: ", error); } }); } } catch (e) { console.log("error in graphQL onCreateOveceventsExhibitorStatus: ", e) } }
Schema:
export const onCreateOveceventsExhibitorStatus = /* GraphQL */ subscription OnCreateOveceventsExhibitorStatus { onCreateOveceventsExhibitorStatus { id datetime status } };
export const createOveceventsExhibitorStatus = /* GraphQL */ mutation CreateOveceventsExhibitorStatus($id: String!, $status: String!) { createOveceventsExhibitorStatus(id: $id, status: $status) { id datetime status } };
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 44 (3 by maintainers)
Hello amplify guys, any luck?
I think this should not be closed, it should not forward users to sites outside of Github / and all code samples / workarounds should be posted HERE.
Same here. I have a react app with three subscriptions and all subscriptions received a “Connection Closed” in a complete random way.
Sometimes the connections are stable and sometimes they are closed after a couple minutes. I will continue to investigate.
Any updates to this issue?
for more info, i also see a comment from webpack after the appsync error:
Not sure if it’s react closing the connection or appsync causing react to print out that command.
that’s my version of react:
“react”: “^16.13.1”, “react-dom”: “^16.13.1”, “react-scripts”: “3.4.3”
This is happening in my team’s application, as well.
We use appsync graphql and vue apollo composable, and I see this error quite a bit. From a bit of trial/error, the issue seems to arise from subscribing/unsubscribing in quick succession.
Vue apollo composable handles subscriptions internally in accordance with component lifecycles (from my understanding), so in this case, mounting and unmounting a component that subscribes/unsubscribe quickly will produce this error. If I wait some time in between mounting/unmounting, the error is less common. Not sure if that’s actually the root cause or a way to get consistent behavior, just wanted to share in case it could help.
We have this issue, no VPN or anything like that. The listed “fixes” are not useful, seems pretty clear that this issue should be re-opened (in my opinion).
This happens intermittently for our subscriptions where the connection is closed by app-sync for seemingly no reason.
Any workarounds for this?
I am running into this problem as well. It happens on web (computer goes to sleep, network change, etc) and iOS and android (app goes into background).
The only solution seems to be refreshing the page or closing and reopening the app. Neither of these solutions are practical, is there another way to refresh the connection?
Hey @mitchitson! After digging into this further, it looks like there are a few different root causes to this issue, and from what I can tell, none appear to be a problem with Amplify itself. Here’s what I’ve found:
1. VPN Issues: This issue is identical to what @mchitson and others are seeing.
Another user on Discord recently ran into the same VPN issue
2. Connection issues breaking the subscription: For users that are using the GraphQL API without DataStore, a disruption in the network connection will close the subscription. There are several discussion on Discord on this. One user posted a solution that could work to re-establish the subscription
3. Dev server disconnecting:
With regards to this other comment from @mchitson:
I haven’t been able to reproduce a scenario where a subscription error causes the dev server to disconnect. Given that you’re seeing
The development server has disconnectedin the console, can you confirm if your dev server stopped running at the time you saw this error? It’s possible there is a timeout happening here, unrelated to Amplify.4. Misconfigured subscriptions:
Regarding the following comment from @mchitson
I’ve run into this before, as well. Without knowing what field is undefined in your app, it’s difficult for me to tell you exactly what’s happening here. However, when I added auth to an API, and was attempting to subscribe to updates without updating the instantiation of the subscription, I was running into a similar issue because I was not implementing the subscription correctly (i.e. a field was missing).
Hope this helps, @mchitson! Please let us know if your issue is not caused by the above.
I just had this happen while doing some stress testing on our app, so sending a lot of updates. Basically we had 2 out of 6 devices get this error at the exact same moment. Please reopen this issue, it doesn’t appear to be related to any of the issues that were outlined above. Not using VPN, Network connection is stable, and the Dev server did not go down. Also I noticed the link to a discord solution for re-subscribing, simply open discord so that doesn’t really help at all.
It is alarming to me that this issue is closed when the issue is obviously still happening to a lot of people. I am going to attempt to setup my own system to resubscribe but, any additional guidance would be appreciated as this issue is a pretty big deal for our app and could force us to change cloud services/tools if we don’t have any good solutions.
I want put a digital store using amplify, now I think that is not secure with all this problems and almost 700 issues.
I agree with @Mootook, in my case, mounting and unmounting a component that subscribes/unsubscribes quickly will produce this error.
Our application is also facing this issue , for us it’s mostly triggered when too many subscription requests are coming ( We have a bulk creation feature - upto 1000 DB entries are created and it listens on their creation ). Not sure if graphQL has a limit on how many concurrent requests it listens
Same issue, no VPN.
Issue should not be closed as there was no mitigation.
The error should also be caught or documentation should be clear that the error will be thrown at unspecified moments in runtime.
Hey mchitson,
Sorry for the ambiguity we made! The issue hasn’t been solved 100% but we have taken actions to reduce the possibility of happening. We believe we can keep the frequency of happening in a very low rate.
As for the re-subscribe question, we’ll provide an update later.
Thanks for the feedbacks!