Automattic/socket.io — pull request #1583 by FredyC (2014-06-03 06:48:14+00:00)
Title: disconnect all sockets on transport close

This should fix #1580.

When transport is closed, this piece of code tries to disconnect all sockets

https://github.com/Automattic/socket.io/blob/master/lib/client.js#L203

It loops over all sockets (spread across different namespaces) and removes them. That would be great, but when it calls `onclose` for the root namespace, it gets to this line:

https://github.com/Automattic/socket.io/blob/master/lib/socket.js#L393

That means socket gets removed from the `Client.sockets` array that is being looped over and next iteration of loop never happens, because array got shorter suddenly.

I have reverted order so it removes all of them correctly and it also looks much better, because it's disconnected from the latest socket instead from the beginning.