GithubHelp home page GithubHelp logo

Comments (9)

lukeredpath avatar lukeredpath commented on July 24, 2024

Interesting. I can only assume what is happening here is that you are trying to unsubscribe from a channel on app resume or in some situation before the connection has been established?

libPusher supports subscribing prior to connection but I never really thought about unsubscribing before connecting. It's not a massive change but I might have to look at this tomorrow when I'm back at my desk.

from libpusher.

lukeredpath avatar lukeredpath commented on July 24, 2024

Just goes to show that assertions are useful for debugging though!

from libpusher.

soffes avatar soffes commented on July 24, 2024

Haha for sure :)

Ya if it fails to connect and the user chooses something in my app, they will subscribe to a channel. If they nav back and choose another, it will unsubscribe from the first and subscribe from the second. Makes sense if they failed to connect.

from libpusher.

lukeredpath avatar lukeredpath commented on July 24, 2024

I have a hunch that trying to subscribe to a channel before connecting will result in the same error. The reason for this is, looking at the code that subscribes to a channel, it looks like I was relying on behaviour of the old socket backend (AsyncSocket) where trying to send data over the socket before it was connected would simply fail.

That meant I could blindly send the "subscribe" message over the socket and have it fail, and then simply loop through the channels and call "subscribe" again when the connection was established, causing them to subscribe if they hadn't subscribed already.

Because SocketRocket (correctly) asserts that sending data before connection is an exception, I think this will now crash.

Could you test this theory and try subscribing to a channel without connecting the Pusher client?

from libpusher.

lukeredpath avatar lukeredpath commented on July 24, 2024

I think the correct solution would be to tease out a better state machine for channels instead of having a boolean "subscribed" flag.

For instance:

Starts as: Unsubcribed

SUBSCRIBE: 
transition to: Waiting For Subscribe

if (connected) {
  // do subscribe
  transition to: Subscribed
}
else {
  // wait for connection
}

UNSUBSCRIBE
transition to: Waiting For Unsubscribe

if (connected) {
  // do unsubscribe
  transition to: Unsubscribed
}
else {
  // wait for connection
}

Then, in PTPusher (the connection delegate), when a connection is established:

foreach (channel that is in Waiting For Subscribe state) {
  [channel subscribe]
}
foreach (channel that is in Waiting For Unsubscribe state) {
  [channel unsubscribe]
  // remove channel 
}

from libpusher.

lukeredpath avatar lukeredpath commented on July 24, 2024

It may be worth having an additional state for private/presence channels such as Waiting For Authorization. I'll have a think about this.

from libpusher.

lukeredpath avatar lukeredpath commented on July 24, 2024

As you can see from my above commit, the more complicated state machine solution simply wasn't necessary. If the connection closes for some reason, for all intents and purposes you are unsubscribed from each channel (there isn't any need to send an unsubscribe message as well). We do mark channels as unsubscribed when disconnected, so the fix was to simply do nothing if you try and call unsubscribe on an already unsubscribed channel.

from libpusher.

soffes avatar soffes commented on July 24, 2024

Perfect. Thanks!

from libpusher.

breezeight avatar breezeight commented on July 24, 2024

Hi @lukeredpath
I'm still seeing a similar bug with a nightly build of Jun 26 2012, see #67
I cannot manage to reproduce but it's happening to a lot of our users. Any idea?

from libpusher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.