You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
My react client switches between 2 AppSync API endpoints using Amplify.configure
When connecting to the first API everything works: mutations are effective and subscriptions receive updates.
But if I switch to the second API only mutations will work. Subscriptions will not receive any updates.
I tracked this down to amplify keeping the websocket connection alive for 1sec after unsubscribing, therefore re-using the first API's websocket connection for the second API's subscriptions.
PS: don't know if it's relevant but I'm using API_KEY for authentication.
Describe the solution you'd like
I would like to be able to force amplify to close existing websocket connections when calling Amplify.configure. Otherwise make sure that new subscriptions that use "old" websocket connections do get triggered.
Describe alternatives you've considered
For now I have to force my components to wait for a few seconds before creating subscriptions.
This gives amplify time to detect existing websockets timeout and close them, forcing a new websocket to be created.
This is quite hacky as I need to artificially go around the async nature of React.
private get awsAppSyncProvider() {
if (!this._awsAppSyncProvider) {
this._awsAppSyncProvider = new AWSAppSyncProvider(this._options);
}
return this._awsAppSyncProvider;
}
private _removeSubscriptionObserver(subscriptionId) {
this.subscriptionObserverMap.delete(subscriptionId);
// Verifying 1000ms after removing subscription in case there are new subscription unmount/mount
setTimeout(this._closeSocketIfRequired.bind(this), 1000);
}
If given enough time between API endpoint switch, Amplify will create a new websocket connection.
In such case subscriptions will work for both endpoints:
Otherwise it will reuse the same connection for a different API endpoint
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
My react client switches between 2 AppSync API endpoints using
Amplify.configure
When connecting to the first API everything works: mutations are effective and subscriptions receive updates.
But if I switch to the second API only mutations will work. Subscriptions will not receive any updates.
I tracked this down to amplify keeping the websocket connection alive for 1sec after unsubscribing, therefore re-using the first API's websocket connection for the second API's subscriptions.
PS: don't know if it's relevant but I'm using API_KEY for authentication.
Describe the solution you'd like
I would like to be able to force amplify to close existing websocket connections when calling
Amplify.configure
.Otherwise make sure that new subscriptions that use "old" websocket connections do get triggered.
Describe alternatives you've considered
For now I have to force my components to wait for a few seconds before creating subscriptions.
This gives amplify time to detect existing websockets timeout and close them, forcing a new websocket to be created.
This is quite hacky as I need to artificially go around the async nature of React.
Additional context
Some observations:
https://github.com/aws-amplify/amplify-js/blob/e1d122bec0fb67eab0a696ee6e0ffa976631e4f0/packages/pubsub/src/PubSub.ts#L45
https://github.com/aws-amplify/amplify-js/blob/61f7478609fce7dd2f25c562aeb887d3f3db4a67/packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts#L386
If given enough time between API endpoint switch, Amplify will create a new websocket connection.
In such case subscriptions will work for both endpoints:
Otherwise it will reuse the same connection for a different API endpoint
The text was updated successfully, but these errors were encountered: