joyent/node — Issue #2507: Unexpected child_process + stdout behavior change from 0.6.5 to 0.6.6
Author: Hainish
Created: 2012-01-11 00:39:33+00:00
State: open

When starting a child process with spawn, a self-exit from the parent process and a subsequent write to stdout from the child causes the child to crash unexpectedly. Bug emerged in 0.6.6, Linux x64.

Observed when running process.js:

process.js
```javascript
var spawn = require("child_process").spawn;

var child = spawn("node", ['child.js']);
child.stdout.on('data', function(data){
if(data.toString().indexOf("Child started") != -1){
console.log("Child process started");
process.exit();
}
});
```

child.js
```javascript
console.log('Child started');

var spawn = require("child_process").spawn;

var grandchild = spawn('node', ['grandchild.js']);
grandchild.stdout.on('data', function(data){
process.stdout.write('I ' + data);
});
```

grandchild.js
```javascript
var x =0;
setInterval(function(){
console.log(x);
x++;
}, 1000);
```