File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ Socket.prototype.connect = function () {
104104 if ( this . connected ) return this ;
105105
106106 this . subEvents ( ) ;
107- this . io . open ( ) ; // ensure open
107+ if ( ! this . io . reconnecting ) this . io . open ( ) ; // ensure open
108108 if ( 'open' === this . io . readyState ) this . onopen ( ) ;
109109 this . emit ( 'connecting' ) ;
110110 return this ;
Original file line number Diff line number Diff line change @@ -433,6 +433,35 @@ describe('connection', function () {
433433
434434 var socket = manager . socket ( '/invalid' ) ;
435435 } ) ;
436+
437+ it ( 'should still try to reconnect twice after opening another socket asynchronously' , function ( done ) {
438+ var manager = io . Manager (
439+ `http://localhost:9823` ,
440+ { reconnect : true , reconnectionAttempts : 2 }
441+ ) ;
442+ var delay = Math . floor ( manager . reconnectionDelay ( ) * manager . randomizationFactor ( ) * 0.5 ) ;
443+ delay = Math . max ( delay , 10 ) ;
444+
445+ var reconnects = 0 ;
446+ var cb = function ( ) {
447+ reconnects ++ ;
448+ } ;
449+
450+ manager . on ( 'reconnect_attempt' , cb ) ;
451+
452+ manager . on ( 'reconnect_failed' , function ( ) {
453+ expect ( reconnects ) . to . be ( 2 ) ;
454+ socket . disconnect ( ) ;
455+ manager . close ( ) ;
456+ done ( ) ;
457+ } ) ;
458+
459+ var socket = manager . socket ( '/room1' ) ;
460+
461+ setTimeout ( ( ) => {
462+ manager . socket ( '/room2' ) ;
463+ } , delay ) ;
464+ } ) ;
436465 }
437466
438467 it ( 'should emit date as string' , function ( done ) {
You can’t perform that action at this time.
0 commit comments