I was writing some tests against remote hosts rather than localhost, and realized that there is a hard cap of 5 after which messages will no longer be received and sent correctly when using engine.io-client from Node.
The cap exists because of http://nodejs.org/api/http.html#http_http_request_options_callback where the default agents agent.maxSockets
is 5.
Since all transports start as http connections, this cap applies to connections that are made simultaneously during a short time even if they use the websockets protocol later on.
The easy way to replicate this is to write a engine.io server that echos back to all connected clients.
Once you have about 3-4 client connections, messages are no longer echoed back to all of the connected clients - only a subset of clients will receive messages back. The rest of the connections do not work correctly.
There is a code path in Node core that removes http connections that have been upgraded to websockets from the pool, but since the initial handshake is still done by xmlhttprequest, doing multiple connections quickly (as in, in a test case that uses multiple engine.io instances to test server internal logic), the limitation still applies.
The fix is simple: https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js#L358
add { agent: false } to disable the connection limit per host.
I'm filing this issue with XMLHttpRequest as well. Hopefully, this issue can be resolved. Once the agent connection limitation has been removed, engine.io-client will need to bump up the version of xmlhttprequest to resolve the issue.