kopia lustrzana https://github.com/c9/core
Fix vfs not always connecting if first node binary in list doesn't exist
We'd first get a EPIPE and then an ENOENT in this scenario, breaking our retry behavior.pull/223/head
rodzic
72a9eb5d4a
commit
4d49d34712
|
@ -1,6 +1,7 @@
|
||||||
var Consumer = require('vfs-socket/consumer').Consumer;
|
var Consumer = require('vfs-socket/consumer').Consumer;
|
||||||
var inherits = require('util').inherits;
|
var inherits = require('util').inherits;
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
exports.Parent = Parent;
|
exports.Parent = Parent;
|
||||||
|
|
||||||
|
@ -23,27 +24,39 @@ function Parent(fsOptions) {
|
||||||
// Override Consumer's connect since the transport logic is internal to this module
|
// Override Consumer's connect since the transport logic is internal to this module
|
||||||
this.connect = connect.bind(this);
|
this.connect = connect.bind(this);
|
||||||
function connect(callback) {
|
function connect(callback) {
|
||||||
|
var _self = this;
|
||||||
try {
|
try {
|
||||||
|
// Check if file exists first; spawn's ENOENT may arrive after other errors
|
||||||
|
if (!fs.existsSync(nodeBin[0]))
|
||||||
|
return tryNext(new Error("Couldn't find valid node binary"));
|
||||||
child = spawn(nodeBin[0], args, options).on("error", tryNext);
|
child = spawn(nodeBin[0], args, options).on("error", tryNext);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return tryNext(e);
|
return done(e);
|
||||||
}
|
}
|
||||||
child.stdin.readable = true;
|
child.stdin.readable = true;
|
||||||
Consumer.prototype.connect.call(this, [child.stdout, child.stdin], tryNext);
|
Consumer.prototype.connect.call(this, [child.stdout, child.stdin], done);
|
||||||
child.on("exit", disconnect);
|
child.on("exit", disconnect);
|
||||||
child.stdin.resume();
|
child.stdin.resume();
|
||||||
var _self = this;
|
|
||||||
// try all possible locations of node before giving up
|
function tryNext(err) {
|
||||||
function tryNext(err, vfs) {
|
if (nodeBin.length > 1) {
|
||||||
if (!child) return;
|
|
||||||
child.removeListener("error", tryNext);
|
|
||||||
child.on("error", function ignore() {});
|
|
||||||
if (err && err.code == "ENOENT" && nodeBin.length > 1) {
|
|
||||||
child = null;
|
|
||||||
nodeBin.shift();
|
nodeBin.shift();
|
||||||
_self.emit("error", err);
|
_self.emit("error", err);
|
||||||
_self.connect(callback);
|
_self.connect(callback);
|
||||||
|
} else {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function done(err, vfs) {
|
||||||
|
if (!child) return;
|
||||||
|
child.removeListener("error", done);
|
||||||
|
child.on("error", function ignore(err) {});
|
||||||
|
child = null;
|
||||||
|
|
||||||
|
if (err && err.code == "ENOENT") {
|
||||||
|
tryNext(err);
|
||||||
} else {
|
} else {
|
||||||
callback(err, vfs);
|
callback(err, vfs);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue