aws-mobile-appsync-sdk-js: Exception when unmounting before subscription websocket connection fully initialized
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
The following exception is thrown when a graphql()-enhanced React component is unmounted before the subscription websocket connection is fully initialized:
TypeError: Cannot read property 'subscriptionFailedCallback' of undefined
at AppSyncRealTimeSubscriptionHandshakeLink.<anonymous> (*******/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js:307:112)
at step (*******/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js:56:23)
at Object.next (*******/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js:37:53)
at fulfilled (*******/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js:28:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
This issue is mentioned in the code base: https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/139a9775eebe6ac8a9df0b72975b522eeb2867cf/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts#L299-L301
We are currently working around it using the following patch:
diff --git a/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js b/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js
index 6eb828e..03ee7e5 100644
--- a/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js
+++ b/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js
@@ -304,7 +304,12 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
}
return [2 /*return*/];
case 5:
- _g = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _g.subscriptionFailedCallback, subscriptionReadyCallback = _g.subscriptionReadyCallback;
+ try {
+ _g = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _g.subscriptionFailedCallback, subscriptionReadyCallback = _g.subscriptionReadyCallback;
+ } catch (e) {
+ return [2 /*return*/];
+ }
+
// This must be done before sending the message in order to be listening immediately
this.subscriptionObserverMap.set(subscriptionId, {
observer: observer,
What is the expected behavior?
Don’t throw exception if unmounting before websocket connection is fully initialized.
Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?
aws-appsync-subscription-link v2.0.1 with aws-appsync-react 3.0.2 Browser and nodejs (in tests)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 17
- Comments: 52 (14 by maintainers)
Commits related to this issue
- fix issue https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/509 — committed to PhileasSystems/aws-mobile-appsync-sdk-js by c10h22 4 years ago
- Updating subscription link to work exactly as Amplify (#616) Fixes: #598 #596 #594 #574 #544 #541 #509 #501 #491 — committed to awslabs/aws-mobile-appsync-sdk-js by elorzafe 3 years ago
- Port over Amplify fix for subscription race conditions (#509) — committed to david-mcafee/aws-mobile-appsync-sdk-js by david-mcafee 2 years ago
- fix: Port over Amplify fix for subscription race conditions (#509) — committed to david-mcafee/aws-mobile-appsync-sdk-js by david-mcafee 2 years ago
- fix: Port over Amplify fix for subscription race conditions for ApolloV2 (#509) — committed to david-mcafee/aws-mobile-appsync-sdk-js by david-mcafee 2 years ago
- fix: Port over Amplify fix for subscription race conditions (#509) (#704) — committed to awslabs/aws-mobile-appsync-sdk-js by david-mcafee 2 years ago
- fix: Port over Amplify fix for subscription race conditions for ApolloV2 (#509) (#705) — committed to awslabs/aws-mobile-appsync-sdk-js by david-mcafee 2 years ago
any updates here?
Any updates on this? this is also affecting aws-amplify version 3.3.7
I am having the same issue in nextjs. three years with the same issue
Still an issue. Fix should be trivial and simple (at least a try/catch).
This is still an issue on v2.1.0
the issue still happening, it’s been years.
@david-mcafee have there been any updates to resolve this? The issue has been going on for two years.
Still seeing this with
Sorry to bump this again, but I still have this issue with version 3.0.11 I will try to create a reproductible sandbox
Edit: sorry I can’t reproduce with a simple example, as my react app is complex I tried simple sandbox, but issue does not happen In my app, the issue is present with simple subscriptions at the root of the app. They are global subscriptions that updates apollo’s cache data for broadcasting UI updates. But I also have user authorization in parallel (app sync, amplify, cognito etc…)
On our side we have cognito and api key links. Some of our operations are used with cognito others with api key.
@dexster, @noobling, @joekendal - these fixes are now available on NPM. Can you please upgrade to the latest versions? Thanks, and please let me know if you need further help!
@dexster, @noobling, and @joekendal - we have 2 other fixes that we are currently working on that will go out with our next release. I’ll update this ticket when the change has been pushed to npm. Thanks!
Likewise still seeing this with 3.0.11 and @apollo/client 3.6.6
@adamduren - we just released the latest version of the AppSync SDK on npm, and this fix is included. Please reach out if you have further questions, thanks!
I still have the issue too
I am still seeing this @4.1.4
I think you can repro it by switching between React pages multiple times.
@noobling Same, I’ve given up and just gone with polling interval as recommended by the Apollo team. Unfortunately AppSync Subscriptions just aren’t ready for customers as:
It’s a shame that Amazon doesn’t place AppSync SDK as a higher priority as Amplify is not suitable for every project.
@david-mcafee Thanks for the feedback. Here’s a code snippet. As other commenters above have mentioned,
subscribeToMoreis the culprit. If you comment it out the error goes away. I also noticed that it only happens in Chromium browsers for me. Safari and Firefox don’t show the errorHow would the code below look like using apollo client?
I, too, am having this issue.
Still having this issue after #616 is merged.
Found a workaround: https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/491#issuecomment-671469907