Browse Source

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

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
25f49f9a80
  1. 13
      lib/base-compiler.js
  2. 1
      package.json

13
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) {

1
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"

Loading…
Cancel
Save