|
|
|
@ -276,36 +276,37 @@ Compile.prototype.exec = function (command, args, options) {
|
|
|
|
|
if (running) treeKill(child.pid); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var stderr = ""; |
|
|
|
|
var stdout = ""; |
|
|
|
|
var streams = { |
|
|
|
|
stderr: "", |
|
|
|
|
stdout: "", |
|
|
|
|
truncated: false |
|
|
|
|
}; |
|
|
|
|
var timeout; |
|
|
|
|
if (timeoutMs) timeout = setTimeout(function () { |
|
|
|
|
logger.warn("Timeout for", command, args, "after", timeoutMs, "ms"); |
|
|
|
|
okToCache = false; |
|
|
|
|
kill(); |
|
|
|
|
stderr += "\nKilled - processing time exceeded"; |
|
|
|
|
streams.stderr += "\nKilled - processing time exceeded"; |
|
|
|
|
}, timeoutMs); |
|
|
|
|
var truncated = false; |
|
|
|
|
child.stdout.on('data', function (data) { |
|
|
|
|
if (truncated) return; |
|
|
|
|
if (stdout.length > maxOutput) { |
|
|
|
|
stdout += "\n[Truncated]"; |
|
|
|
|
truncated = true; |
|
|
|
|
kill(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stdout += data; |
|
|
|
|
}); |
|
|
|
|
child.stderr.on('data', function (data) { |
|
|
|
|
if (truncated) return; |
|
|
|
|
if (stderr.length > maxOutput) { |
|
|
|
|
stderr += "\n[Truncated]"; |
|
|
|
|
truncated = true; |
|
|
|
|
kill(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stderr += data; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function setupStream(stream, name) { |
|
|
|
|
stream.on('data', function (data) { |
|
|
|
|
if (streams.truncated) return; |
|
|
|
|
if (streams[name].length > maxOutput) { |
|
|
|
|
streams[name] += "\n[Truncated]"; |
|
|
|
|
streams.truncated = true; |
|
|
|
|
kill(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
streams[name] += data; |
|
|
|
|
}); |
|
|
|
|
stream.on('error', function (err) { |
|
|
|
|
logger.error('Error with stream:', err); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setupStream(child.stdout, 'stdout'); |
|
|
|
|
setupStream(child.stderr, 'stderr'); |
|
|
|
|
child.on('exit', function (code) { |
|
|
|
|
logger.debug({type: 'exited', code: code}); |
|
|
|
|
if (timeout !== undefined) clearTimeout(timeout); |
|
|
|
@ -320,8 +321,8 @@ Compile.prototype.exec = function (command, args, options) {
|
|
|
|
|
if (timeout !== undefined) clearTimeout(timeout); |
|
|
|
|
var result = { |
|
|
|
|
code: code, |
|
|
|
|
stdout: stdout, |
|
|
|
|
stderr: stderr, |
|
|
|
|
stdout: streams.stdout, |
|
|
|
|
stderr: streams.stderr, |
|
|
|
|
okToCache: okToCache |
|
|
|
|
}; |
|
|
|
|
logger.debug({type: "executed", command: command, args: args, result: result}); |
|
|
|
|