From 90f046f8960f216f86a646d9938b42a4639e3308 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 14 Oct 2020 17:18:57 +0530 Subject: [PATCH] prevent long-running worker tasks from timing out --- lib/workers/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/workers/index.js b/lib/workers/index.js index ddee0ddde..d0a9a66f5 100644 --- a/lib/workers/index.js +++ b/lib/workers/index.js @@ -81,7 +81,8 @@ Workers.initialize = function (Env, config, _cb) { }; var drained = true; - var sendCommand = function (msg, _cb) { + var sendCommand = function (msg, _cb, opt) { + opt = opt || {}; var index = getAvailableWorkerIndex(); var state = workers[index]; @@ -119,7 +120,9 @@ Workers.initialize = function (Env, config, _cb) { delete state.tasks[txid]; }))); - response.expect(txid, cb, 180000); + // default to timing out affter 180s if no explicit timeout is passed + var timeout = typeof(opt.timeout) !== 'undefined'? opt.timeout: 180000; + response.expect(txid, cb, timeout); state.worker.send(msg); }; @@ -354,13 +357,17 @@ Workers.initialize = function (Env, config, _cb) { Env.evictInactive = function (cb) { sendCommand({ command: 'EVICT_INACTIVE', - }, cb); + }, cb, { + timeout: 1000 * 60 * 300, // time out after 300 minutes (5 hours) + }); }; Env.runTasks = function (cb) { sendCommand({ command: 'RUN_TASKS', - }, cb); + }, cb, { + timeout: 1000 * 60 * 10, // time out after 10 minutes + }); }; Env.writeTask = function (time, command, args, cb) {