Skip to content

Commit

Permalink
Merge 9dad85d into 4be4400
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 11, 2019
2 parents 4be4400 + 9dad85d commit f157070
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions index.js
Expand Up @@ -14,6 +14,7 @@ const onExit = require('signal-exit');
const stdio = require('./lib/stdio');

const TEN_MEGABYTES = 1000 * 1000 * 10;
const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;

const SPACES_REGEXP = / +/g;

Expand Down Expand Up @@ -224,18 +225,27 @@ function setKillTimeout(kill, signal, options, killResult) {
return;
}

const forceKillAfter = Number.isInteger(options.forceKillAfter) ?
options.forceKillAfter :
5000;
setTimeout(() => kill('SIGKILL'), forceKillAfter).unref();
const timeout = getForceKillAfterTimeout(options);
setTimeout(() => {
kill('SIGKILL');
}, timeout).unref();
}

function shouldForceKill(signal, options, killResult) {
return ((typeof signal === 'string' &&
signal.toUpperCase() === 'SIGTERM') ||
signal === os.constants.signals.SIGTERM) &&
options.forceKill !== false &&
killResult;
function shouldForceKill(signal, {forceKill}, killResult) {
return isSigterm(signal) && forceKill !== false && killResult;
}

function isSigterm(signal) {
return signal === os.constants.signals.SIGTERM ||
(typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
}

function getForceKillAfterTimeout({forceKillAfter}) {
if (Number.isInteger(forceKillAfter)) {
return forceKillAfter;
}

return DEFAULT_FORCE_KILL_TIMEOUT;
}

const execa = (file, args, options) => {
Expand Down

0 comments on commit f157070

Please sign in to comment.