amplify-js: PubSub unsubscribe breaks subscribe to topics again

Describe the bug Updating aws-amplify version to “1.1.40” broke our PubSub subscribe function when calling it again after unsubscribe.

For example, if I subscribe to [‘myTopic1’,‘myTopic2’] and then call unsubscribe and subscribe again to those topics later I can no longer receive any IoT messages to related topics. I do not receive any errors when subscribing again. it just does not work.

If I manually use “@aws-amplify/pubsub”: “1.1.0”, I do not have the same problem. However, with the latest “@aws-amplify/pubsub”: “1.1.2” this problem exists.

To Reproduce

  1. install aws-amplify “1.1.40” or “@aws-amplify/pubsub”: “1.1.2”
  2. subscribe to some topics let subscriptions = PubSub.subscribe(['myTopic1','myTopic2']).subscribe({...
  3. Send IoT messages to those topics and test that client receives messages correctly.
  4. call subscriptions.unsubscribe()
  5. Subscribe again to same topics subscriptions = PubSub.subscribe(['myTopic1','myTopic2']).subscribe({...
  6. Send IoT messages to those topics.
  7. No messages are received.

We use the following Amplify configurations:

Amplify.configure({Auth: { mandatorySignIn: false, region: ..., identityPoolId: ..., userPoolWebClientId: ... }...

Amplify.addPluggable(new AWSIoTProvider({ aws_pubsub_region: ..., aws_pubsub_endpoint: ... }))

Expected behavior I expect AWS PubSub to work again after unsubscribe.

Related discussion: https://github.com/aws-amplify/amplify-js/issues/3039 https://github.com/aws-amplify/amplify-js/issues/2692

Aws-amplify PubSub seems to be very unreliable solution for Websockets. We have been using it for 1-2 years now and had a lot of different connection problems. For us it is really important that our clients have successful websocket connection that is easy to reinitialise when connection breaks or fails. Our clients are connected to multiple different topics and topics are sometimes unsubscribed and subscribed again. If someone has more reliable solutions and better libraries to recommend related to websockets in AWS environment, I would appreciate it.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (11 by maintainers)

Most upvoted comments

@elorzafe - I just noticed this was pushed into the Amplify master. Its great you’ve made some changes to fix these issues.

One thing I’m still not sure about is how to handle network disconnect/reconnects. Does this now reconnect automatically if the app goes into the background or network is lost?

@elorzafe and other amplify-js guys: What is the status of this issue and when you will release the fix? It’s been almost two month now since you reopened this case. Would be really useful to get this fixed asap.

Encountering exact same situation as @mevert. Also I would add the following : I don’t believe this problem is dependant on the platform but here is the issue i have:

  • React-native application subscribes to a few topics.
  • Go out of the application for a few minutes (application goes to background)
  • Come back to application (application comes back to foreground)
  • Paho.Client triggers onConnectionLost.
  • MqttOverWSProvider calls the onDisconnect method
  • Every topics observers raise the error function with Disconnected error message.
  • In the error function, I unsubscribe and subscribe again to the topic.
  • Publish messages then don’t work…

Effectively, in the error function, if i unsubscribe, wait a second and then subscribe again … i receive published messages on those topics. Waiting a second before subscribing again is not very optimal and more of a patch then solving the problem really. I agree with @mevert that having a way to know when subscription is available would be necessary for those special cases.

Thank you @elorzafe !! 😃