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

Room leaving not synced with the cluster on disconnect. #831

Closed
c-spencer opened this issue Apr 13, 2012 · 6 comments
Closed

Room leaving not synced with the cluster on disconnect. #831

c-spencer opened this issue Apr 13, 2012 · 6 comments

Comments

@c-spencer
Copy link

Disconnects cause a socket to leave all rooms, but these leaves are not broadcast, so other workers never remove a disconnected socket from their rooms array.

Simple cluster test:

cluster = require 'cluster'

if cluster.isMaster
  cluster.fork() for i in [1..2]

  # Restart dead workers.
  cluster.on 'death', (worker) ->
    console.log "worker #{worker.pid} died"
    cluster.fork()

else
  resp = """
      <script src="/socket.io/socket.io.js"></script>
      <script> var socket = new io.connect(); </script>
      <h1>Hello World.</h1>
    """

  redis = require 'redis'
  sio = require 'socket.io'
  express = require 'express'

  app = express.createServer()
  app.get '/', (req, res) -> res.send resp
  app.listen(3334)

  io = sio.listen(app)

  io.configure ->
    store = new sio.RedisStore
    io.set 'store', store
    io.set 'log level', 1

  io.sockets.on 'connection', (socket) ->
    console.log "#{process.pid} client connect #{socket.id}"
    socket.join 'secret_room'
    io.sockets.in('secret_room').emit 'join', 'client'

    socket.on 'disconnect', ->
      console.log "#{process.pid} did disconnect of #{socket.id}"

  setInterval ->
    console.log "#{process.pid}", io.sockets.manager.rooms['/secret_room']
  , 10000

Sample from opening in browser, and refreshing once:

42058 heard connect of 774353954845812834
42057 client connect 774353954845812834
42057 [ '774353954845812834' ]
42058 [ '774353954845812834' ]
42057 did disconnect of 774353954845812834
42057 heard connect of 18990979991629805474
42058 client connect 18990979991629805474
42057 [ '18990979991629805474' ]
42058 [ '774353954845812834', '18990979991629805474' ]

There are two fixes I've tried that work, but I'm unsure as to which is the best solution:

Inside the room leaving loop of Manager.prototype.onDisconnect:

this.store.publish('leave', id, room);

Or inside Manager.prototype.onClientDisconnect:

this.store.publish('disconnect', id);

I notice that most of the client disconnection sync is done via 'disconnect:' + id, which is the reason why the disconnections aren't picked up by other workers. Is there a strong reason not to use globally published disconnect events?

@wavded
Copy link

wavded commented Apr 13, 2012

I am experiencing this issue as well

@wavded
Copy link

wavded commented Apr 13, 2012

looks like this also happens for custom events too, only gets pushed to one instance

@jjoschyy
Copy link

Confirm this. Using

this.store.publish('leave', id, room);

solved it for me.

@lassikin
Copy link

got this issue with current what's available on npm. disconnects would leave the default room "" populated.

"Or inside Manager.prototype.onClientDisconnect:
this.store.publish('disconnect', id);" seems to fix the issue.

@FREEZX
Copy link

FREEZX commented Mar 12, 2013

Why is this still not official?

@yuxizhou
Copy link

yuxizhou commented May 9, 2013

I face the same problem, any solution?

This issue was closed.
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

6 participants