Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee8d0fb

Browse files
author
Tony Kovanen
committed
Fix namespace iterator in disconnect
1 parent 2c1b611 commit ee8d0fb

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ Client.prototype.onclose = function(reason){
199199
this.destroy();
200200

201201
// `nsps` and `sockets` are cleaned up seamlessly
202-
this.sockets.forEach(function(socket){
202+
var socket;
203+
while (socket = this.sockets.shift()) {
203204
socket.onclose(reason);
204-
});
205+
}
205206

206207
this.decoder.destroy(); // clean up decoder
207208
};

test/socket.io.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,33 @@ describe('socket.io', function(){
395395
}
396396
});
397397
});
398+
399+
it('should disconnect both default and custom namespace upon disconnect', function(done){
400+
var srv = http();
401+
var sio = io(srv);
402+
srv.listen(function(){
403+
var lolcats = client(srv, '/lolcats');
404+
var total = 2;
405+
var totald = 2;
406+
var s;
407+
sio.of('/', function(socket){
408+
socket.on('disconnect', function(reason){
409+
--totald || done();
410+
});
411+
--total || close();
412+
});
413+
sio.of('/lolcats', function(socket){
414+
s = socket;
415+
socket.on('disconnect', function(reason){
416+
--totald || done();
417+
});
418+
--total || close();
419+
});
420+
function close(){
421+
s.disconnect(true);
422+
}
423+
});
424+
});
398425
});
399426
});
400427

0 commit comments

Comments
 (0)