diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 946c1108..28f18238 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -31,6 +31,7 @@ var child_process = require('child_process'), utils = require('./utils'), quote = require('shell-quote'), _ = require('underscore-node'), + treeKill = require('tree-kill'), logger = require('./logger').logger; function Compile(compiler, env) { @@ -265,12 +266,17 @@ Compile.prototype.exec = function (command, args, options) { env: env, detached: process.platform == 'linux' }); + var running = true; + function kill() { + if (running) treeKill(child.pid); + } var stderr = ""; var stdout = ""; var timeout; if (timeoutMs) timeout = setTimeout(function () { + logger.warn("Timeout for", command, args, "after", timeoutMs, "ms"); okToCache = false; - child.kill(); + kill(); stderr += "\nKilled - processing time exceeded"; }, timeoutMs); var truncated = false; @@ -279,7 +285,7 @@ Compile.prototype.exec = function (command, args, options) { if (stdout.length > maxOutput) { stdout += "\n[Truncated]"; truncated = true; - child.kill(); + kill(); return; } stdout += data; @@ -289,7 +295,7 @@ Compile.prototype.exec = function (command, args, options) { if (stderr.length > maxOutput) { stderr += "\n[Truncated]"; truncated = true; - child.kill(); + kill(); return; } stderr += data; @@ -297,6 +303,7 @@ Compile.prototype.exec = function (command, args, options) { child.on('exit', function (code) { logger.debug({type: 'exited', code: code}); if (timeout !== undefined) clearTimeout(timeout); + running = false; }); return new Promise(function (resolve, reject) { child.on('error', function (e) { diff --git a/package.json b/package.json index 0a987e9d..738bf154 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "serve-favicon": "2.3.x", "serve-static": "1.10.x", "temp": "0.8.x", + "tree-kill": "1.1.x", "underscore-node": "*", "shell-quote": "1.6.x", "winston": "2.2.x"