From 4d49d34712bf2d5bbd8732242511f17e83012df3 Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Wed, 4 Nov 2015 11:18:22 +0000 Subject: [PATCH 1/3] 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. --- node_modules/vfs-child/parent.js | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/node_modules/vfs-child/parent.js b/node_modules/vfs-child/parent.js index cf6b53c5..f98d320c 100644 --- a/node_modules/vfs-child/parent.js +++ b/node_modules/vfs-child/parent.js @@ -1,6 +1,7 @@ var Consumer = require('vfs-socket/consumer').Consumer; var inherits = require('util').inherits; var spawn = require('child_process').spawn; +var fs = require("fs"); exports.Parent = Parent; @@ -23,27 +24,39 @@ function Parent(fsOptions) { // Override Consumer's connect since the transport logic is internal to this module this.connect = connect.bind(this); function connect(callback) { + var _self = this; 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); } catch (e) { - return tryNext(e); + return done(e); } 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.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; + + function tryNext(err) { + if (nodeBin.length > 1) { nodeBin.shift(); _self.emit("error", err); _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 { callback(err, vfs); } From c1ea5744a0057150628e3c4f38274e546b74f441 Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Wed, 4 Nov 2015 11:19:43 +0000 Subject: [PATCH 2/3] Cleanup old ENOENT approach --- node_modules/vfs-child/parent.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/node_modules/vfs-child/parent.js b/node_modules/vfs-child/parent.js index f98d320c..2c1dc7a9 100644 --- a/node_modules/vfs-child/parent.js +++ b/node_modules/vfs-child/parent.js @@ -26,7 +26,6 @@ function Parent(fsOptions) { function connect(callback) { var _self = this; 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); @@ -54,12 +53,7 @@ function Parent(fsOptions) { child.removeListener("error", done); child.on("error", function ignore(err) {}); child = null; - - if (err && err.code == "ENOENT") { - tryNext(err); - } else { - callback(err, vfs); - } + callback(err, vfs); } } From d3098fa2f0bc06c98631acf24b438b539bf06239 Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Wed, 4 Nov 2015 13:26:24 +0000 Subject: [PATCH 3/3] Fix null.kill() TypeError: Cannot call method 'kill' of null at Parent.disconnect (/home/ubuntu/workspace/node_modules/vfs-child/parent.js:65:15) at Parent.master.destroy (/home/ubuntu/workspace/plugins/c9.vfs.server/vfs.js:142:16) # Please enter the commit message for your changes. Lines starting at Vfs.destroy (/home/ubuntu/workspace/plugins/c9.vfs.server/vfs.js:109:21) # with '#' will be ignored, and an empty message aborts the commit. at EventEmitter.entry.destroy (/home/ubuntu/workspace/plugins/c9.vfs.server/cache.js:131:40) # On branch fix-vfs at remove (/home/ubuntu/workspace/plugins/c9.vfs.server/cache.js:110:23) # Changes to be committed: at null._onTimeout (/home/ubuntu/workspace/plugins/c9.vfs.server/cache.js:143:21) # modified: node_modules/vfs-child/parent.js at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) # Changes not staged for commit: --- node_modules/vfs-child/parent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node_modules/vfs-child/parent.js b/node_modules/vfs-child/parent.js index 2c1dc7a9..d51fca64 100644 --- a/node_modules/vfs-child/parent.js +++ b/node_modules/vfs-child/parent.js @@ -49,11 +49,11 @@ function Parent(fsOptions) { } function done(err, vfs) { - if (!child) return; + if (!callback) return; child.removeListener("error", done); child.on("error", function ignore(err) {}); - child = null; callback(err, vfs); + callback = null; } }