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

PubSub Javascript: How to detect websocket closed and reconnect? #4459

Closed
markmacau opened this issue Nov 25, 2019 · 11 comments
Closed

PubSub Javascript: How to detect websocket closed and reconnect? #4459

markmacau opened this issue Nov 25, 2019 · 11 comments
Assignees
Labels
PubSub Related to PubSub category question General question

Comments

@markmacau
Copy link

markmacau commented Nov 25, 2019

** Which Category is your question related to? **
PubSub Javascript(vue)

** What AWS Services are you utilizing? **
PubSub, IoT, Cognito(Unauth)

** Provide additional details e.g. code snippets **
Somehow my MQTT connection drops even after successfully subscribed a topic and send/receive messages.

  1. How can I detect/monitor MQTT connection status? In other word, How can I access AWSIoTProvider created by Amplify.addPluggable?

  2. After MQTT disconnect and even I unsubscribe then subscribe topic again, I cannot publish message any more with error "AMQJS0011E Invalid state not connected".

So far only solution is to reload page. Is there any better way to recover session?

  1. Above "AMQJS0011E Invalid state not connected." error can be a trigger to reconnect socket. How to set eventlisteners on such errors?
@markmacau markmacau added the question General question label Nov 25, 2019
@jordanranz jordanranz added the PubSub Related to PubSub category label Dec 27, 2019
@escar
Copy link

escar commented Feb 28, 2020

Having this issue too, any way to overcome this problem?

@ericclemmons ericclemmons added this to the PubSub reconnect sockets milestone Apr 28, 2020
@houmark
Copy link

houmark commented May 21, 2020

It's really starting to become a problem for us, that we cannot in any way check the current connection status and reconnect in any reliable way.

The simplest use case is a browser tab staying open while the user putting her computer to sleep, then resumes work without refreshing the UI/tab. The UI will stop providing realtime updates, and there's no way we have found, where we can even request a connection status.

@kevin-mitchell
Copy link

Also interested in tracking this!

@dcoellarb
Copy link

any updates on this?

@nitindatta
Copy link

anyone found workaround for this.

@pieterbergmans
Copy link

This seems to happen quite often. Any solutions?

@stocaaro
Copy link
Member

stocaaro commented Aug 22, 2022

Some good news. Detecting socket status changes just got a whole lot easier with new Hub messages.

Work is inflight to add automated reconnection.

@nubpro
Copy link
Contributor

nubpro commented Aug 23, 2022

Some good news. Detecting socket status changes just got a whole lot easier with new Hub messages.

Work is inflight to add automated reconnection.

might want to check on the link you posted...

@stocaaro
Copy link
Member

Good catch. Thanks to @abdallahshaban557 for proactively fixing this!

@stocaaro
Copy link
Member

stocaaro commented Oct 4, 2022

Reconnection is now staged on the next tag in preparation for release in aws-amplify v5. To test against this update install the next tag version of the aws-amplify packages your project is using. eg yarn add aws-amplify@next.

With this change any disrupted connection will attempt to reconnect when possible. Reconnection can be expected to trigger 5 seconds after the resources to reconnect are available. If the network is disrupted in a way that can't be detected, reconnection will be attempted every minute until the connection is recovered.

Note that missed messages will not backfill on recovery. If you need to trigger behavior to catch up missed messaged on recovery, this should be possible to implement using the connection state Hub messages released last month.

@stocaaro
Copy link
Member

Good news. Automated Reconnection is now available on the latest aws-amplify release! Review the updated subscription docs and consider any application behavior you may want to add to best meet your users needs when subscriptions reconnect.

Please review our breaking change guidance before upgrading your application.

To upgrade Amplify to version 5, run the following in your project folder:

yarn add aws-amplify@latest

Check package.json to see if your project uses other @aws-amplify/* packages directly and upgrade them to latest as well.

With this behavior released, I am closing this issue as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PubSub Related to PubSub category question General question
Projects
None yet
Development

No branches or pull requests