Permalink
Browse files

Kill entire process tree of a child when the timeout is reached. Fixes

  • Loading branch information...
1 parent 0ee3cf2 commit 25f49f9a80447a0365d52881dbcffd8a8df58b6c @mattgodbolt committed Jan 11, 2017
Showing with 11 additions and 3 deletions.
  1. +10 −3 lib/base-compiler.js
  2. +1 −0 package.json
View
@@ -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,14 +295,15 @@ Compile.prototype.exec = function (command, args, options) {
if (stderr.length > maxOutput) {
stderr += "\n[Truncated]";
truncated = true;
- child.kill();
+ kill();
return;
}
stderr += data;
});
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) {
View
@@ -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"

0 comments on commit 25f49f9

Please sign in to comment.