mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Prevent server crash in handleClientReady
The client might have disconnected between callbacks so don't try to write to the session before checking this. The main callback of this function now has a single check at its top. Removed a redundant check halfway through the callback. Also normalized use of client.id for the session index instead of a mix of client.id and sessionId. Added some explanatory comments.
This commit is contained in:
parent
413ddb393e
commit
2e72a1e489
1 changed files with 25 additions and 23 deletions
|
@ -882,6 +882,13 @@ function handleClientReady(client, message)
|
||||||
},
|
},
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
|
//Check that the client is still here. It might have disconnected between callbacks.
|
||||||
|
if(sessioninfos[client.id] === undefined)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Check if this author is already on the pad, if yes, kick the other sessions!
|
//Check if this author is already on the pad, if yes, kick the other sessions!
|
||||||
if(pad2sessions[padIds.padId])
|
if(pad2sessions[padIds.padId])
|
||||||
{
|
{
|
||||||
|
@ -896,10 +903,9 @@ function handleClientReady(client, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save in sessioninfos that this session belonges to this pad
|
//Save in sessioninfos that this session belonges to this pad
|
||||||
var sessionId=String(client.id);
|
sessioninfos[client.id].padId = padIds.padId;
|
||||||
sessioninfos[sessionId].padId = padIds.padId;
|
sessioninfos[client.id].readOnlyPadId = padIds.readOnlyPadId;
|
||||||
sessioninfos[sessionId].readOnlyPadId = padIds.readOnlyPadId;
|
sessioninfos[client.id].readonly = padIds.readonly;
|
||||||
sessioninfos[sessionId].readonly = padIds.readonly;
|
|
||||||
|
|
||||||
//check if there is already a pad2sessions entry, if not, create one
|
//check if there is already a pad2sessions entry, if not, create one
|
||||||
if(!pad2sessions[padIds.padId])
|
if(!pad2sessions[padIds.padId])
|
||||||
|
@ -908,7 +914,7 @@ function handleClientReady(client, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Saves in pad2sessions that this session belongs to this pad
|
//Saves in pad2sessions that this session belongs to this pad
|
||||||
pad2sessions[padIds.padId].push(sessionId);
|
pad2sessions[padIds.padId].push(client.id);
|
||||||
|
|
||||||
//prepare all values for the wire
|
//prepare all values for the wire
|
||||||
var atext = Changeset.cloneAText(pad.atext);
|
var atext = Changeset.cloneAText(pad.atext);
|
||||||
|
@ -973,9 +979,7 @@ function handleClientReady(client, message)
|
||||||
clientVars.userName = authorName;
|
clientVars.userName = authorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sessioninfos[client.id] !== undefined)
|
//If this is a reconnect, we don't have to send the client the ClientVars again
|
||||||
{
|
|
||||||
//This is a reconnect, so we don't have to send the client the ClientVars again
|
|
||||||
if(message.reconnect == true)
|
if(message.reconnect == true)
|
||||||
{
|
{
|
||||||
//Save the revision in sessioninfos, we take the revision from the info the client send to us
|
//Save the revision in sessioninfos, we take the revision from the info the client send to us
|
||||||
|
@ -986,13 +990,11 @@ function handleClientReady(client, message)
|
||||||
{
|
{
|
||||||
//Send the clientVars to the Client
|
//Send the clientVars to the Client
|
||||||
client.json.send({type: "CLIENT_VARS", data: clientVars});
|
client.json.send({type: "CLIENT_VARS", data: clientVars});
|
||||||
//Save the revision in sessioninfos
|
//Save the current revision in sessioninfos, should be the same as in clientVars
|
||||||
sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
|
sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save the revision and the author id in sessioninfos
|
|
||||||
sessioninfos[client.id].author = author;
|
sessioninfos[client.id].author = author;
|
||||||
}
|
|
||||||
|
|
||||||
//prepare the notification for the other users on the pad, that this user joined
|
//prepare the notification for the other users on the pad, that this user joined
|
||||||
var messageToTheOtherUsers = {
|
var messageToTheOtherUsers = {
|
||||||
|
|
Loading…
Reference in a new issue