From 4ddbce2dbcc7f428f45bb5cf792cc9049cf4f695 Mon Sep 17 00:00:00 2001 From: alanning Date: Tue, 14 Jan 2014 13:39:54 -0500 Subject: [PATCH 1/3] improve error reporting and use rolling timeout --- lib/sources/git.js | 77 ++++++++++++++++++++++++++++++++++++++++------ package.json | 1 + 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/lib/sources/git.js b/lib/sources/git.js index 2f4e3b3..cd5fb32 100644 --- a/lib/sources/git.js +++ b/lib/sources/git.js @@ -4,9 +4,11 @@ var wrench = require('wrench'); var fs = require('fs'); var url = require('url'); var spawn = require('child_process').spawn; -var exec = require('child_process').exec; +var exec = require('rolling_timeout_exec').exec; var fstream = require('fstream'); +var ROLLING_TIMEOUT = 15000; + GitSource = function(basePath, config) { // Setup @@ -27,6 +29,7 @@ GitSource = function(basePath, config) { } }; + GitSource.prototype.packagePath = function() { return path.join(this.basePath, this.packageNamespace(), this.commit); }; @@ -107,14 +110,25 @@ GitSource.prototype._pull = function(fn) { }; GitSource.prototype._clone = function(fn) { - var self = this; + var self = this, + child, + timedOut = false, + command = 'git clone --progress ' + + this.url + ' "' + this.sourcePath + '"', + options = { rollingTimeout: ROLLING_TIMEOUT }; + if (!fs.existsSync(this.sourcePath)) { - exec('git clone ' + self.url + ' "' + this.sourcePath + '"', function(err, stdout, stderr) { - if (err) + child = exec(command, options, function(err, stdout, stderr) { + if (err) { + reportErrors(err, stdout, stderr, timedOut); throw "There was a problem cloning repo: " + self.url + "\nPlease check https://github.com/oortcloud/meteorite/blob/master/CONTRIBUTING.md#troubleshooting for potential explanations."; + } fn(); }); + child.on('rolling-timeout', function () { + timedOut = true; + }); } else { fn(); } @@ -151,13 +165,26 @@ GitSource.prototype._load = function(fn) { }; GitSource.prototype._checkout = function(fn) { - var self = this; - - exec('git checkout ' + (this.commit || this.head), {cwd: this.sourcePath}, function(err, stdout, stderr) { - if (err) - throw "There was a problem checking out " + self.checkoutType + ": " + (self.commit || self.head); + var self = this, + child, + timedOut = false, + command = 'git checkout ' + (this.commit || this.head), + options = { + rollingTimeout: ROLLING_TIMEOUT, + cwd: this.sourcePath + }; + + child = exec(command, options, function(err, stdout, stderr) { + if (err) { + reportErrors(err, stdout, stderr, timedOut); + throw "There was a problem checking out " + + self.checkoutType + ": " + (self.commit || self.head); + } fn(); }); + child.on('rolling-timeout', function () { + timedOut = true; + }) }; GitSource.prototype._updateSubmodules = function(fn) { @@ -219,9 +246,39 @@ GitSource.prototype.overrides = function(otherSource) { } GitSource.getCommitForDir = function(path, fn) { - exec('git rev-parse HEAD', { cwd: path }, function (err, stdout) { + var self = this, + child, + timedOut = false, + command = 'git rev-parse HEAD', + options = { + rollingTimeout: ROLLING_TIMEOUT, + cwd: path + }; + + child = exec(command, options, function (err, stdout, stderr) { + if (err) { + reportErrors(err, stdout, stderr, timedOut); + } fn(stdout.trim()); }); + child.on('rolling-timeout', function () { + timedOut = true; + }); }; module.exports = GitSource; + + + + +function reportErrors (err, stdout, stderr, timedOut) { + var timedOutMsg = 'child process timed out, no activity for ' + + ROLLING_TIMEOUT/1000 + ' seconds'; + + if (timedOut) { + console.error(timedOutMsg, '\n'); + } + console.error('ERROR:', err.code, err.message, '\n'); + console.error('STDOUT:', stdout, '\n'); + console.error('STDERR:', stderr, '\n'); +} diff --git a/package.json b/package.json index e1c7b72..15dbf04 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ , "prompt": "0.2.11" , "colors": "0.6.0-1" , "async": "0.2.9" + , "rolling_timeout_exec": ">=0.0.1" } , "devDependencies": { "mocha": ">=1.2.2" From cc47b1d7c78776fc0a8ca94af02acf748d16314c Mon Sep 17 00:00:00 2001 From: alanning Date: Thu, 16 Jan 2014 23:45:14 -0500 Subject: [PATCH 2/3] support '--progress' flag to git clone command --- spec/support/bin/git | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/support/bin/git b/spec/support/bin/git index 5eb2f43..8b1e7cf 100755 --- a/spec/support/bin/git +++ b/spec/support/bin/git @@ -21,16 +21,17 @@ if (command === 'clone') { if (!fs.existsSync(cachePath)) wrench.mkdirSyncRecursive(cachePath); - var repoUrl = args[1]; + var destPath = args.pop(); + var repoUrl = args.pop(); var repoParts = repoUrl.replace('.git', '').split('/'); var repoName = repoParts.pop(); var repoUser = repoParts.pop(); - var destPath = args[2]; var repoCachePath = path.join(cachePath, repoUser, repoName); if (!fs.existsSync(repoCachePath)) { - var git = spawn('/usr/local/bin/git', ['clone', repoUrl, repoCachePath]); + var runCommand = args.join(' '); + var git = spawn('/usr/local/bin/git', [runCommand, repoUrl, repoCachePath]); git.on('exit', function() { copyRepo(repoCachePath, destPath); From 670ccb6526ec8dcb08c99a313babe58753078384 Mon Sep 17 00:00:00 2001 From: alanning Date: Fri, 17 Jan 2014 00:54:33 -0500 Subject: [PATCH 3/3] fix params to clone spawn call --- spec/support/bin/git | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/support/bin/git b/spec/support/bin/git index 8b1e7cf..94f224f 100755 --- a/spec/support/bin/git +++ b/spec/support/bin/git @@ -29,9 +29,9 @@ if (command === 'clone') { var repoCachePath = path.join(cachePath, repoUser, repoName); if (!fs.existsSync(repoCachePath)) { - - var runCommand = args.join(' '); - var git = spawn('/usr/local/bin/git', [runCommand, repoUrl, repoCachePath]); + args.push(repoUrl); + args.push(repoCachePath); + var git = spawn('/usr/local/bin/git', args); git.on('exit', function() { copyRepo(repoCachePath, destPath);