joyent/node — pull request #4104 by aadityabhatia (2012-10-09 01:18:20+00:00)
Title: cluster 'listening' handler's port number when worker calls listen(0)

http://nodejs.org/api/cluster.html#cluster_event_listening

According to the documentation, the event handler receives the `address` object with `port` property, which is set to the port that the worker passed to `listen()`. This covers the case where user manually specifies a port number, but if use specifies `0`, a random port is assigned.

In such a situation, the event handler should receive the randomly assigned port number, not `0`.

```
cluster = require 'cluster'
if not cluster.isMaster
app = require('express').createServer()
app.get '/*', (req, res) -> res.send "Hello Cluster"
app.listen 0, ->
console.log "I am listening on port " + app.address().port
// output: I am listening on port 56789
else
cluster.on 'listening', (worker, address) ->
console.log "W#{worker.id} listening on port " + address.port
// output: W1 listening on port 0
cluster.fork()
```