From bad920e28dc2a1ae609e44574ee5bc51900979e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Thu, 16 Feb 2012 23:11:52 +0100 Subject: [PATCH 1/3] fixes #417 and #360 --- node/handler/PadMessageHandler.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index 19aa1f9b2..c7cffaa3f 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -859,6 +859,10 @@ function handleClientReady(client, message) //get the authorname & colorId function(callback) { + if(sessioninfos[sessionID] === undefined){ + callback(); + return; + } async.parallel([ function(callback) { @@ -883,7 +887,7 @@ function handleClientReady(client, message) function (callback) { //Jump over, if this session is the connection session - if(sessionID != client.id) + if(sessionID != client.id && socketio.sockets.sockets[sessionID] !== undefined) { //Send this Session the Notification about the new user socketio.sockets.sockets[sessionID].json.send(messageToTheOtherUsers); From 97b7f0707f1a95ce3e70f5e29c43f502d1fc6938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Thu, 16 Feb 2012 23:35:00 +0100 Subject: [PATCH 2/3] Add further checks to make sure sessioninfos[sessionID] is !== undefined --- node/handler/PadMessageHandler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index c7cffaa3f..a93c79da7 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -887,7 +887,9 @@ function handleClientReady(client, message) function (callback) { //Jump over, if this session is the connection session - if(sessionID != client.id && socketio.sockets.sockets[sessionID] !== undefined) + if(sessionID != client.id && + socketio.sockets.sockets[sessionID] !== undefined && + sessioninfos[sessionID] !== undefined) { //Send this Session the Notification about the new user socketio.sockets.sockets[sessionID].json.send(messageToTheOtherUsers); From fe6c5e1cfe89447613ff22ee037849134055bcf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Fri, 17 Feb 2012 11:40:29 +0100 Subject: [PATCH 3/3] restructured and commented fixes #417 and #360 in order to make code more intuitive --- node/handler/PadMessageHandler.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index a93c79da7..48f0aa988 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -853,20 +853,27 @@ function handleClientReady(client, message) //Run trough all sessions of this pad async.forEach(pad2sessions[message.padId], function(sessionID, callback) { - var sessionAuthorName, sessionAuthorColorId; - + var author, socket, sessionAuthorName, sessionAuthorColorId; + + //Since sessioninfos might change while being enumerated, check if the + //sessionID is still assigned to a valid session + if(sessioninfos[sessionID] !== undefined && + socketio.sockets.sockets[sessionID] !== undefined){ + author = sessioninfos[sessionID].author; + socket = socketio.sockets.sockets[sessionID]; + }else { + // If the sessionID is not valid, callback(); + callback(); + return; + } async.series([ //get the authorname & colorId function(callback) { - if(sessioninfos[sessionID] === undefined){ - callback(); - return; - } async.parallel([ function(callback) { - authorManager.getAuthorColorId(sessioninfos[sessionID].author, function(err, value) + authorManager.getAuthorColorId(author, function(err, value) { if(ERR(err, callback)) return; sessionAuthorColorId = value; @@ -875,7 +882,7 @@ function handleClientReady(client, message) }, function(callback) { - authorManager.getAuthorName(sessioninfos[sessionID].author, function(err, value) + authorManager.getAuthorName(author, function(err, value) { if(ERR(err, callback)) return; sessionAuthorName = value; @@ -887,12 +894,10 @@ function handleClientReady(client, message) function (callback) { //Jump over, if this session is the connection session - if(sessionID != client.id && - socketio.sockets.sockets[sessionID] !== undefined && - sessioninfos[sessionID] !== undefined) + if(sessionID != client.id) { //Send this Session the Notification about the new user - socketio.sockets.sockets[sessionID].json.send(messageToTheOtherUsers); + socket.json.send(messageToTheOtherUsers); //Send the new User a Notification about this other user var messageToNotifyTheClientAboutTheOthers = { @@ -904,7 +909,7 @@ function handleClientReady(client, message) "colorId": sessionAuthorColorId, "name": sessionAuthorName, "userAgent": "Anonymous", - "userId": sessioninfos[sessionID].author + "userId": author } } };