@@ -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+
326332var isConnectionBusy = false ;
327333var connectionSocketQueue = [ ] ;
328334var isDisconnectBusy = false ;
329335var disconnectSocketQueue = [ ] ;
330336
331337function 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