Skip to content

Commit 9ee940e

Browse files
committed
Double kill jobs
1 parent e1c62f0 commit 9ee940e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,21 @@ function getRepoPath(name) {
324324
function startJobTimer(job, kill_children = false) {
325325
const timeout = config.timeout || 8 * 60000; // How long to wait for the tests to run
326326
return setTimeout(() => {
327+
let log = _log.extend('job_timer');
327328
console.log('Max test time exceeded');
328329
log(kill_children ? 'Killing all processes' : 'Ending test process');
329330
let pid = job._child.pid;
331+
log('Killing process(es) for job #%g, pid = %d', job.id, pid);
330332
job._child.kill();
331-
if (kill_children) {
332-
kill(pid);
333-
}
333+
if (kill_children) kill(pid);
334+
// Give the processes 1 minute before sending a more aggressive signal
335+
return setTimeout(() => {
336+
if (job._child && job._child.exitCode == null) {
337+
log('Failed to kill job process(es); sending SIGKILL (job #%g, pid = %d)', job.id, pid);
338+
job._child.kill('SIGKILL');
339+
if (kill_children) kill(pid, 'SIGKILL');
340+
}
341+
}, 60000)
334342
}, timeout);
335343
}
336344

@@ -534,10 +542,10 @@ async function buildRoutine(job) {
534542
*/
535543
function computeCoverage(job) {
536544
if (typeof job.data.coverage !== 'undefined' && job.data.coverage) {
537-
console.log('Coverage already computed for job #' + job.id);
545+
console.log('Coverage already computed for job #%g', job.id);
538546
return;
539547
}
540-
console.log('Updating coverage for job #' + job.id);
548+
console.log('Updating coverage for job #%g', job.id);
541549
const xmlPath = path.join(config.dataPath, 'reports', job.data.sha, 'CoverageResults.xml');
542550
const modules = listSubmodules(process.env.REPO_PATH);
543551
return Coverage(xmlPath, job.data.repo, job.data.sha, modules).then(obj => {

test/lib.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,21 @@ describe('Test startJobTimer:', function () {
340340
clock.tick(config.timeout + 1);
341341
});
342342

343+
it('expect SIGKILL', function (done) {
344+
// Test second timeout for tests where SIGTERM fails to end process
345+
const childProcess = {
346+
kill: (sig) => {
347+
if (sig === 'SIGKILL') done();
348+
},
349+
pid: 10108
350+
};
351+
const job = queue.add({});
352+
job.child = childProcess;
353+
lib.startJobTimer(job);
354+
// Skip to the end...
355+
clock.tick(config.timeout + 60001); // timeout + ~1 minute
356+
});
357+
343358
after(() => {
344359
clock.restore();
345360
});

0 commit comments

Comments
 (0)