Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Reconnect Channels on Socket Reset #2

wants to merge 5 commits into


None yet
1 participant

bitmage commented Dec 22, 2012

Reconnecting all the channels when the socket resets allows the communication stream to continue (relatively) uninterrupted. At the very least it will heal itself without a page refresh.

Related to: wearefractal/protosock#3

@bitmage bitmage commented on an outdated diff Dec 22, 2012

@channels[name] ?= new Channel name, @ssocket
+ # if we just got a new socket, reconnect the channels
+ connect: (socket) ->
+ reconnectChannels = =>
+ for name, channel of @channels
+ @channels[name] = new Channel name, socket
+ @channels[name].listeners = channel.listeners
+ @channels[name].events = channel.events
+ setTimeout reconnectChannels, 100

bitmage Dec 22, 2012

The timeout shouldn't be necessary, but pulsar requires the server channels to have already been initialized before the client tries to connect. So without the timeout, the client tries to set up its channels before the server has re-initialized them on its side.

We could avoid the setTimeout, and a number of other issues by queuing channel requests on the server side. If the channel doesn't exist yet, you can queue the listener, then once the channel is created add any queued listeners. This would make the timing issues around channel creation much less touchy, and as a result would give greater reliability to the library.

bitmage commented Feb 12, 2013

We've got this built into the master branch now, in a cleaner way. Closing.

@bitmage bitmage closed this Feb 12, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment