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

This commit is contained in:
Wu Cheng-Han 2016-07-05 16:11:18 +08:00
parent f7a4f8f8c2
commit 40478f4eff

View file

@ -323,17 +323,27 @@ function clearSocketQueue(queue, socket) {
} }
} }
function connectNextSocket() {
isConnectionBusy = false;
if (connectionSocketQueue.length > 0)
startConnection(connectionSocketQueue[0]);
}
var isConnectionBusy = false; var isConnectionBusy = false;
var connectionSocketQueue = []; var connectionSocketQueue = [];
var isDisconnectBusy = false; var isDisconnectBusy = false;
var disconnectSocketQueue = []; var disconnectSocketQueue = [];
function finishConnection(socket, note, user) { function finishConnection(socket, note, user) {
// if no valid info provided will drop the client
if (!socket || !note || !user) { if (!socket || !note || !user) {
if (note) delete note; if (note) delete note;
if (user) delete user; if (user) delete user;
connectionSocketQueue.pop(); if (socket)
isConnectionBusy = false; clearSocketQueue(connectionSocketQueue, socket);
else
connectionSocketQueue.shift();
connectNextSocket();
return; return;
} }
//check view permission //check view permission
@ -356,9 +366,7 @@ function finishConnection(socket, note, user) {
//clear finished socket in queue //clear finished socket in queue
clearSocketQueue(connectionSocketQueue, socket); clearSocketQueue(connectionSocketQueue, socket);
//seek for next socket //seek for next socket
isConnectionBusy = false; connectNextSocket();
if (connectionSocketQueue.length > 0)
startConnection(connectionSocketQueue[0]);
if (config.debug) { if (config.debug) {
var noteId = socket.noteId; var noteId = socket.noteId;
@ -436,7 +444,7 @@ function failConnection(code, err, socket) {
logger.error(err); logger.error(err);
// clear error socket in queue // clear error socket in queue
clearSocketQueue(connectionSocketQueue, socket); clearSocketQueue(connectionSocketQueue, socket);
isConnectionBusy = false; connectNextSocket();
// emit error info // emit error info
socket.emit('info', { socket.emit('info', {
code: code code: code