From 50504ed09b54a3d94b2092b9f1d7807bf959a83e Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 17 Oct 2017 12:45:18 +0300 Subject: [PATCH] Fix possible race condition when attaching clients --- src/server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server.js b/src/server.js index 2a0cab96..0190fc2c 100644 --- a/src/server.js +++ b/src/server.js @@ -236,6 +236,8 @@ function index(req, res, next) { function initializeClient(socket, client, token, lastMessage) { socket.emit("authorized"); + client.clientAttach(socket.id, token); + socket.on("disconnect", function() { client.clientDetach(socket.id); }); @@ -430,8 +432,6 @@ function initializeClient(socket, client, token, lastMessage) { socket.join(client.id); const sendInitEvent = (tokenToSend) => { - client.clientAttach(socket.id, token); - let networks = client.networks; if (lastMessage > -1) { @@ -456,7 +456,7 @@ function initializeClient(socket, client, token, lastMessage) { if (!Helper.config.public && token === null) { client.generateToken((newToken) => { - token = newToken; + client.attachedClients[socket.id].token = token = newToken; client.updateSession(token, getClientIp(socket), socket.request);