Fix vfs-child/parent error handling

Fixes crash when child prints to stdout/stderr,
triggering unhandled EPIPE error
pull/117/merge
Lennart Kats 2015-07-25 19:42:50 +00:00
rodzic 8723eca18f
commit 31218bbc1d
1 zmienionych plików z 7 dodań i 2 usunięć

9
node_modules/vfs-child/parent.js wygenerowano vendored
Wyświetl plik

@ -23,17 +23,22 @@ function Parent(fsOptions) {
// Override Consumer's connect since the transport logic is internal to this module
this.connect = connect.bind(this);
function connect(callback) {
child = spawn(nodeBin[0], args, options);
try {
child = spawn(nodeBin[0], args, options).on("error", tryNext);
}
catch (e) {
return tryNext(e);
}
child.stdin.readable = true;
Consumer.prototype.connect.call(this, [child.stdout, child.stdin], tryNext);
child.on("exit", disconnect);
child.on("error", tryNext);
child.stdin.resume();
var _self = this;
// try all possible locations of node before giving up
function tryNext(err, vfs) {
if (!child) return;
child.removeListener("error", tryNext);
child.on("error", function ignore() {});
if (err && err.code == "ENOENT" && nodeBin.length > 1) {
child = null;
nodeBin.shift();