aws-mobile-appsync-sdk-js icon indicating copy to clipboard operation
aws-mobile-appsync-sdk-js copied to clipboard

Exception when subscription handshaking times out after subscription observer state has already been cleaned up

Open chrisjameskirkham opened this issue 5 years ago • 3 comments

Do you want to request a feature or report a bug?

bug

What is the current behavior?


A `TypeError` occurs when destructuring a subscription observer that has been removed before handshaking completes.

TypeError: Cannot read property 'observer' of undefined

    at AppSyncRealTimeSubscriptionHandshakeLink.Object.<anonymous>.AppSyncRealTimeSubscriptionHandshakeLink._timeoutStartSubscriptionAck (/.../node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js:708:82)
    at /.../node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js:323:68
    at Timeout.callback [as _onTimeout] (/.../node_modules/jsdom/lib/jsdom/browser/Window.js:678:19)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

This is occuring here: https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/139a9775eebe6ac8a9df0b72975b522eeb2867cf/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts#L710-L713

We have patched the distributed package with:

-        var _a = this.subscriptionObserverMap.get(subscriptionId), observer = _a.observer, query = _a.query, variables = _a.variables;
+        var _a = this.subscriptionObserverMap.get(subscriptionId);
+
+        // This check avoids an error when this `_timeoutStartSubscriptionAck` handler runs after `_removeSubscriptionObserver`, which will have deleted it from the map.
+        if (!_a) {
+            return;
+        }
+
+        var observer = _a.observer, query = _a.query, variables = _a.variables;

What is the expected behavior?

When establishing a subscription, the handshaking timeout should fail gracefully if the subscription gets removed before handshaking completes.

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)

This issue is related to https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/509 with the patch mentioned there applied.

chrisjameskirkham avatar Jan 31 '20 16:01 chrisjameskirkham

This is still an issue on v2.1.0

StefanSmith avatar Apr 16 '20 13:04 StefanSmith

Screen Shot 2020-12-21 at 11 07 32 am

dylan-westbury avatar Dec 21 '20 00:12 dylan-westbury

These PR1 & PR2 have been opened with related fixes.

KvNGCzA avatar Jan 07 '21 00:01 KvNGCzA