Merge pull request #1639 from thelounge/xpaw/fix-attach-race-condition
Fix possible race condition when attaching clients
This commit is contained in:
commit
4d544143b4
@ -236,6 +236,8 @@ function index(req, res, next) {
|
|||||||
function initializeClient(socket, client, token, lastMessage) {
|
function initializeClient(socket, client, token, lastMessage) {
|
||||||
socket.emit("authorized");
|
socket.emit("authorized");
|
||||||
|
|
||||||
|
client.clientAttach(socket.id, token);
|
||||||
|
|
||||||
socket.on("disconnect", function() {
|
socket.on("disconnect", function() {
|
||||||
client.clientDetach(socket.id);
|
client.clientDetach(socket.id);
|
||||||
});
|
});
|
||||||
@ -430,8 +432,6 @@ function initializeClient(socket, client, token, lastMessage) {
|
|||||||
socket.join(client.id);
|
socket.join(client.id);
|
||||||
|
|
||||||
const sendInitEvent = (tokenToSend) => {
|
const sendInitEvent = (tokenToSend) => {
|
||||||
client.clientAttach(socket.id, token);
|
|
||||||
|
|
||||||
let networks = client.networks;
|
let networks = client.networks;
|
||||||
|
|
||||||
if (lastMessage > -1) {
|
if (lastMessage > -1) {
|
||||||
@ -456,7 +456,7 @@ function initializeClient(socket, client, token, lastMessage) {
|
|||||||
|
|
||||||
if (!Helper.config.public && token === null) {
|
if (!Helper.config.public && token === null) {
|
||||||
client.generateToken((newToken) => {
|
client.generateToken((newToken) => {
|
||||||
token = newToken;
|
client.attachedClients[socket.id].token = token = newToken;
|
||||||
|
|
||||||
client.updateSession(token, getClientIp(socket), socket.request);
|
client.updateSession(token, getClientIp(socket), socket.request);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user