Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force creation of a new websocket for subscriptions when switching between APIs #7156

Open
raphaelfavier opened this issue Nov 10, 2020 · 1 comment
Labels
AppSync Related to AppSync issues feature-request Request a new feature GraphQL Related to GraphQL API issues

Comments

@raphaelfavier
Copy link

raphaelfavier commented Nov 10, 2020

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:

         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:
    image

  • Otherwise it will reuse the same connection for a different API endpoint
    image

@raphaelfavier raphaelfavier added the feature-request Request a new feature label Nov 10, 2020
@sammartinez sammartinez added the AppSync Related to AppSync issues label Nov 10, 2020
@raphaelfavier
Copy link
Author

Hello,

is there any update/progress on the issue?

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AppSync Related to AppSync issues feature-request Request a new feature GraphQL Related to GraphQL API issues
Projects
None yet
Development

No branches or pull requests

3 participants