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

Unsubscribing and subscribing very quickly causes unexpected behavior #106

Open
rafaelcorreiapoli opened this issue Aug 31, 2016 · 3 comments

Comments

@rafaelcorreiapoli
Copy link

rafaelcorreiapoli commented Aug 31, 2016

Hi, consider this code:

const b = function() {
1  const handler = asteroid.subscribe('pokemons')
2  const id = handler.id
3  asteroid.unsubscribe(id)
4  const handler2 = asteroid.subscribe('pokemons')
}

Until line 3 everything works as expected. I get all "added" messages and "removed" messages
The problem is after resubscribing (on line 4) I don't get the "insert" messages again.
I'm trying to understand how asteroid and ddp.js works inside to find clues about this behaviour and I think that is something related to the asynchronicity of unsub and sub

(Obviously the "b" function is hypothetical but something similar is happening on my App because of React's HMR)

@rafaelcorreiapoli
Copy link
Author

rafaelcorreiapoli commented Aug 31, 2016

const c = function() {
 const handler = asteroid.subscribe('pokemons')
 const id = handler.id
 asteroid.unsubscribe(id)
 setTimeout(() => {
  const handler2 = asteroid.subscribe('pokemons')
 }, 500) 
}

This makes it works as expected... so I think that the problem is related to asynchronicity

On meteor's own implementation, it works as expected

const m = function() {
const handler = Meteor.subscribe('pokemons')
handler.stop()
const handler2 = Meteor.subscribe('pokemons')
}

after calling m, I have the documents on the client provided by the "pokemons'' publication

@clayne11
Copy link

clayne11 commented Oct 3, 2016

This happens because when you unsub from a subscription, it doesn't actually get deleted from the subscription cache until the server replies with a nosub message.

https://github.com/mondora/asteroid/blob/master/src/base-mixins/subscriptions.js#L81-L86

IMO the subscription should be deleted immediately when you unsubscribe.

https://github.com/mondora/asteroid/blob/master/src/base-mixins/subscriptions.js#L63-L65

@boldkhuu
Copy link

boldkhuu commented Dec 8, 2016

I faced this problem and it's solved by below:

const c = function() {
  const handler = asteroid.subscribe('pokemons')
  const id = handler.id
  asteroid.unsubscribe(id)
  asteroid.subscriptions.cache.del(id) // deleting from cache synchronously
  const handler2 = asteroid.subscribe('pokemons')
}

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

No branches or pull requests

3 participants