davinkevin / AngularStompDK

Angular service to communicate to Stomp-Websocket
http://davinkevin.github.io/AngularStompDK/
Apache License 2.0
36 stars 12 forks source link

Lost subscriptions when first connection attempt failed #38

Closed baczus closed 8 years ago

baczus commented 8 years ago

Hi,

I found out that library doesn't subscribe to topics when first connection attempt failed. I think the problem occurs because during each connection new promise is created and old promise is not resolved. So we have a following situation:

  1. Function '$setConnection' creates new promise (A)
  2. User subscribes to topic
  3. Function 'subscribe' waits for resolving promise A
  4. Connection fails, reconnect
  5. '$setConnection' creates new promise (B)
  6. Promise (A) in 'subscribe' function will never be resolved.
davinkevin commented 8 years ago

Thanks for this issue...

That is a regression, in the past, the Stomp connection failure reject the promise and after that the processus of reconnection starts...

To solve this, I've had the reject operation in the Stomp connection failure callback, and a second parameter to the subscription to save the connection initiated to use this in the $reconectAll.

I've checked in my simple project to see if it's working, all seems to be good. I launch the front page with BrowserSync, don't start the backend... error in console... and when I launch the backend, the front-end connect and replay the connection scenario.

Tell me if you find something wrong about it.

Thanks

baczus commented 8 years ago

Thanks for fixing the issue, but I found another problem. When you reject the promise, you create new one after timeout. So if you have 30 seconds to reconnect, during this time your promise is rejected. In this situation functions send and unsubscribe won't work properly. Maybe there is an option to create new promise earlier?