stream-utils/duplex-child-process — pull request #4 by jeromew (2014-05-06 23:22:19+00:00)
Title: handle ECONNRESET upon early stdin end

I tracked down an error I have with 'identity' in a specific scenario but I am sure I can happen in other cases when the spawned process decides that it does not want any more data on stdin.

my bug came from a specific identify setup, with a png image available a a buffer in memory, and telling identify we already know it is a png image (`png:-`)

here is a test that throws the ECONNRESET from time to time (once every 10 `make test` I would say)

````
it('should accept early child.stdin termination', function (done) {
var buffer = fs.readFileSync(image_png);
var child = new Child_Process();
child.end(buffer);
child
.spawn('identify', ['-format', '%m', 'PNG:-'])
.on('error', done)
.on('readable', function () {
var data = this.read();
if (data) {
assert.equal('PNG', data.toString('utf8').trim())
done()
}
})
})
````

note that I tried to do a

this._stdin.once('finish', function() { that._writer.unpipe(that._stdin); });

but that did not work. The ECONNRESET probably comes because identify does something to the stdin socket before node calls the finish event.

Tell me if this makes sense to you.

At this stage I am intercepting the error in my code but I would prefer not having to reference `_stdin.on(..)` outside of duplex-child-process.