ry/node_chat — Issue #21: Potential session conflict
Author: Rob--W
Created: 2012-02-01 11:07:06+00:00
State: open

In `server.js`, a "random" session id is generated and assigned as follows:

var session = {
nick: nick,
id: Math.floor(Math.random()*99999999999).toString(),

After `var session =`, the session id is assigned without any checks:

sessions[session.id] = session;

**In a rare case, the session ID may already exist.**

I propose the following change:

// Generate a sid which does not exist yet
var sid;
do {
sid = Math.floor(Math.random()*99999999999).toString();
} while(sid in sessions);

var session = {
nick: nick,
id: sid,