joyent/node — pull request #3429 by SuperShabam (2012-06-13 17:39:25+00:00)
Title: Fixes issue #3428 - Net module bug under clustering - server.listen(0); port == 0; assigns the same port to each worker

Single-line fix. Should not share clustered connection if we are connection on port 0 because we are trying to create a new randomly allocated port, not share.

The cluster module caches and stores connections. So, if we try to allow the cluster to open port 0 for us, it stores that we have a connection for port 0 (even though its port resolves to some actual value later). The problem then happens when we open another connection to port 0 because the cluster module already has a cached connection for "port 0".

To get around this, only consult the cluster module if we are specifying the port. If we are using port 0, we have no intention in sharing this connection among workers and we should not use the cluster module to share connections.