wamp.io icon indicating copy to clipboard operation
wamp.io copied to clipboard

A Client Quits Will Cause The Server Down

Open Kenzku opened this issue 12 years ago • 1 comments

When it happen:

I opened two clients in different windows on Safari. One sent a message and the other could received, but if either of the clients quit, such as by close the window, it would trigger an error on the server.

What is the output:

The Node.js output says:

wamp.io/lib/server.js:90
      delete self.topics[topic][client.id];
                                      ^
TypeError: Cannot convert null to object
    at WebSocket.Server.onConnection (/Users/Ken/Documents/Projects/wamp.io/lib/server.js:90:39)
    at WebSocket.EventEmitter.emit (events.js:123:20)
    at WebSocket.cleanupWebsocketResources (/Users/Ken/Documents/Projects/wamp.io/node_modules/ws/lib/WebSocket.js:649:23)
    at Socket.EventEmitter.emit (events.js:90:17)
    at TCP.onread (net.js:417:51)

What I thought:

If added one line before the delete self.topics[topic][client.id];

console.log(self.topics[0]);

it outputs undefined, moreover.

the self.topics looks like an object rather than an array, e.g.:

{ 'event:firstevent': { '585972943854826': true } }

Kenzku avatar Mar 14 '13 09:03 Kenzku

I couldn't understand what does the following line does,

90 delete self.topics[topic][client.id];

but it seems if changed to this way might work:

var toplicsKeys = Object.keys(client.topics);
      for (var topic in toplicsKeys) {
          delete self.topics[toplicsKeys[topic]][client.id];
      }

So, could you please also explain what is your code does on client.on('close, function(){ ... }); in lib/server.js

Kenzku avatar Mar 14 '13 11:03 Kenzku