joyent/node — Issue #2866: ipc between node processes - child memory keep growing
Author: matomesc
Created: 2012-03-03 20:54:04+00:00
State: open

So i have this setup where a child process keeps messages to the parent and the parent's stdout is redirected to `/dev/null`

```javascript
var cp = require('child_process');

if (!process.send) {
// master
var child = cp.fork('./test.js');
child.on('message', function (msg) {
process.stdout.write(msg);
});
} else {
// child
while (true) {
process.send('hey there\n');
}
}
```
Now, the child's memory keeps growing and i want to understand why this is happening. I think it's because the buffer on the child's side keeps growing as there is too much data for the pipe to handle.

Also, due to the `while()` the child's event loop is blocked - what are the implications of this? Is the data not being piped properly since we're blocked and there isn't another event loop to drain the buffer?

Note that if using `process.nextTick()` rather than the `while()` i do get constant memory usage:

```javascript
var cp = require('child_process');

if (!process.send) {
// master
var child = cp.fork('./test.js');
child.on('message', function (msg) {
process.stdout.write(msg);
});
} else {
// child
function add() {
process.nextTick(function () {
process.send('hey there\n');
add();
});
}
add();
}
```