From 1d0a601e4f0476429d1fc640010414039d5b22a5 Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Mon, 14 Mar 2016 18:43:41 +1100 Subject: [PATCH] Fix (release.js): Protect against EPIPE bombs from npmjs (closes #645). * Adds epipebomb package, which swallows EPIPE errors. * Adds a default timeout to `toExecPromise`, and the ability to override it. * Increases timeout for npm publish. --- package.json | 1 + tools/release.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3ad96c6725..4909d94e3a 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "async": "^1.5.2", "chai": "^3.5.0", "colors": "^1.1.2", + "epipebomb": "^0.1.1", "express": "^4.13.4", "fs-extra": "^0.26.5", "fs-promise": "^0.5.0", diff --git a/tools/release.js b/tools/release.js index e196fd651c..8c4a0fa776 100755 --- a/tools/release.js +++ b/tools/release.js @@ -12,6 +12,9 @@ const colors = require("colors"); const MAIN_BRANCH = "develop"; let DEBUG = false; +//See: https://github.com/w3c/respec/issues/645 +require("epipebomb")(); + colors.setTheme({ data: "grey", debug: "cyan", @@ -24,12 +27,13 @@ colors.setTheme({ verbose: "cyan", warn: "yellow", }); + function rel(f) { return path.join(__dirname, f); } function git(cmd) { - if(DEBUG){ + if (DEBUG) { console.log(colors.debug(`Pretending to run: ${"git " + colors.prompt(cmd)}`)); return Promise.resolve(); } @@ -132,12 +136,15 @@ const Promps = { } }; -function toExecPromise(cmd) { +function toExecPromise(cmd, timeout) { + if (!timeout) { + timeout = 20000; + } return new Promise((resolve, reject) => { const id = setTimeout(() => { reject(new Error(`Command took too long: ${cmd}`)); proc.kill("SIGTERM"); - }, 20000); + }, timeout); const proc = exec(cmd, (err, stdout) => { clearTimeout(id); if (err) { @@ -154,7 +161,7 @@ function getBranchState() { const remote = yield git(`rev-parse @{u}`); const base = yield git(`merge-base @ @{u}`); let result = ""; - switch(local){ + switch (local) { case remote: result = "up-to-date"; break; @@ -205,7 +212,8 @@ async.task(function * () { yield git("push origin gh-pages"); yield git("push --tags"); console.log(colors.info(" 📡 Publishing to npm...")); - yield toExecPromise("npm publish"); + // We give npm publish 1 minute to time out, as it can be slow. + yield toExecPromise("npm publish", 60000); } catch (err) { console.error(colors.red(err)); process.exit(1);