Fix socket.io issue #1862

See https://github.com/Automattic/socket.io/issues/1862 for the repro
case.  Basically, if connecting to one namespace at the same time
as disconnecting from another, the connection gets lost.  We should
keep the connection alive as long as anybody is "connecting".

This code shrinks the code slightly and fixes this bug.