joyent/node — Issue #2475: process.on('message', function() {}); duplicates events when working with a cluster
Author: baryshev
Created: 2012-01-06 09:29:22+00:00
State: open

```javascript
var cluster = require('cluster');
var http = require('http');

if (cluster.isMaster) {
for (var i = 0; i < 2; i++) {
var worker = cluster.fork();
worker.on('message', function(msg) {
worker.send({ 'ok': Math.random() });
});
}
} else {
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
process.send({ cmd: 'request' });
process.on('message', function(msg) {
console.log(msg);
});
}).listen(80);
}
```

Each request is fired the same event message N-times. Where N - total number of requests.

console.log() result for 4 requests in row:

{ ok: 0.6853540265001357 }
{ ok: 0.2907937625423074 }
{ ok: 0.2907937625423074 }
{ ok: 0.8598960456438363 }
{ ok: 0.8598960456438363 }
{ ok: 0.8598960456438363 }
{ ok: 0.9613411626778543 }
{ ok: 0.9613411626778543 }
{ ok: 0.9613411626778543 }
{ ok: 0.9613411626778543 }

Expected:

{ ok: 0.6853540265001357 }
{ ok: 0.2907937625423074 }
{ ok: 0.8598960456438363 }
{ ok: 0.9613411626778543 }