LearnBoost/socket.io — Issue #714: on('disconnect') not fired from a namespace.
Author: CrypticSwarm
Created: 2012-01-10 01:22:11+00:00
State: open

The disconnect event isn't being triggered in a namespace if the namespace was created after a user joins.

After reading the code and trying to understand what is going on from what I can tell it stems from the namespace's sockets not being set to 'readable'. It appears sockets are initialized with readable true for any namespace that exists when a client connects, but if a new namespace is created then it gets its socket set on the first handle packet is called.

https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L659
https://github.com/LearnBoost/socket.io/blob/master/lib/namespace.js#L265

Changing line 265 of namespace.js to pass true as the second parameter does cause the disconnects to be fired properly. However I don't know if it would have other impacts as well.