Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Reconnect Channels on Socket Reset #2

Closed
wants to merge 5 commits into from
+1,670 −1,746

1 participant

@bitmage

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

lib/Client.coffee
((6 lines not shown))
@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
bitmage added a note

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.

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

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

@bitmage bitmage closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 22, 2012
  1. reconnect channels when the socket resets

    bitmage authored
  2. built

    bitmage authored
Commits on Jan 30, 2013
  1. copy stack to new channel

    bitmage authored
  2. built

    bitmage authored
Commits on Feb 11, 2013
  1. added failing test for channel reconnect

    bitmage authored
Something went wrong with that request. Please try again.