Skip to content

Commit 40478f4

Browse files
committed
Fix realtime on finishConnection might not clear and connect next socket in queue and should use shift instead of pop on remove invalid socket in queue
1 parent f7a4f8f commit 40478f4

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

lib/realtime.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,27 @@ function clearSocketQueue(queue, socket) {
323323
}
324324
}
325325

326+
function connectNextSocket() {
327+
isConnectionBusy = false;
328+
if (connectionSocketQueue.length > 0)
329+
startConnection(connectionSocketQueue[0]);
330+
}
331+
326332
var isConnectionBusy = false;
327333
var connectionSocketQueue = [];
328334
var isDisconnectBusy = false;
329335
var disconnectSocketQueue = [];
330336

331337
function finishConnection(socket, note, user) {
338+
// if no valid info provided will drop the client
332339
if (!socket || !note || !user) {
333340
if (note) delete note;
334341
if (user) delete user;
335-
connectionSocketQueue.pop();
336-
isConnectionBusy = false;
342+
if (socket)
343+
clearSocketQueue(connectionSocketQueue, socket);
344+
else
345+
connectionSocketQueue.shift();
346+
connectNextSocket();
337347
return;
338348
}
339349
//check view permission
@@ -356,9 +366,7 @@ function finishConnection(socket, note, user) {
356366
//clear finished socket in queue
357367
clearSocketQueue(connectionSocketQueue, socket);
358368
//seek for next socket
359-
isConnectionBusy = false;
360-
if (connectionSocketQueue.length > 0)
361-
startConnection(connectionSocketQueue[0]);
369+
connectNextSocket();
362370

363371
if (config.debug) {
364372
var noteId = socket.noteId;
@@ -436,7 +444,7 @@ function failConnection(code, err, socket) {
436444
logger.error(err);
437445
// clear error socket in queue
438446
clearSocketQueue(connectionSocketQueue, socket);
439-
isConnectionBusy = false;
447+
connectNextSocket();
440448
// emit error info
441449
socket.emit('info', {
442450
code: code

0 commit comments

Comments
 (0)