Socket.io broadcast stops working if user leaves namespace then rejoins

My situation is this:

  1. User A creates namespace with name of his choice
  2. User B joins created namespace
  3. User A sends message which is broadcasted by the server and received by User B
  4. User B sends message which is broadcasted by the server and received by User A
  5. User B leaves namespace through client-side socket.disconnect();
  6. User B rejoins namespace
  7. User B sends message which is broadcasted by the server and IS received by User A
  8. User A sends message which is broadcasted by the server and NOT received by User B

Important Notes:

  • If User B refreshes the page and rejoins that namespace while User A remains there, he can then send and receive messages normally again.
  • When User B is in the 'not working' state, he still seems to be getting events through socket emit. In other words, only User A receives events initiated by both parties, where User B only receives events initiated by himself.

Why, when User B leaves and rejoins does the server become a one way street relative to him?

Server Code:

var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('socket.io').listen(server);

server.listen(8080);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

var connection_function = function(socket) {
    socket.on('join_chat', function(data) {
        socket.set('fb_id', data.id);
        socket.emit('joined_chat', data);
        socket.broadcast.emit('joined_chat', data);
        socket.namespace.connected_users[data.id] = data;
    });
    socket.on('send_message', function(data) {
        data.user = socket.namespace.connected_users[socket.store.data.fb_id];
        socket.emit('recieve_msg', data);
        socket.broadcast.emit('recieve_msg', data);
    });
    socket.on('disconnect', function () {
        socket.broadcast.emit('left_chat', socket.namespace.connected_users[socket.store.data.fb_id]);
        delete socket.namespace.connected_users[socket.store.data.fb_id];
    });

}
var chats = {};

var main = io.of('/main');
main.on('connection', function(socket) {
    socket.on('new_chat', function(data, fn) {
        if(!chats.hasOwnProperty(data.chat_name)) {
            chats[data.chat_name] = io.of('/' + data.chat_name);
            chats[data.chat_name].on('connection', connection_function);
            chats[data.chat_name].connected_users = {};
        }
        fn(data);
    });
});

Update (Friday October 12, 2012)

After some more research it appears that the issue may be with socket.io:

https://github.com/LearnBoost/socket.io-client/issues/251

https://github.com/LearnBoost/socket.io-client/issues/473

Are you sure you don't want to be using socket.io rooms instead?

socket.join(roomName);

io.socket.in(roomName).emit(.....;

I have a working example of rooms here: https://github.com/rcpeters/openMap_me/blob/master/app.js