Updated lock handling

This commit is contained in:
Andris Reinman 2021-06-21 20:32:25 +03:00
parent 0c7ad4c107
commit 14ecd5cf90
4 changed files with 17 additions and 19 deletions

View file

@ -9,7 +9,6 @@ const AcmeChallenge = require('./acme-challenge');
const pkg = require('../../package.json');
const { normalizeDomain } = require('../tools');
const Lock = require('ioredfour');
const util = require('util');
const log = require('npmlog');
const { Resolver } = require('dns').promises;
const resolver = new Resolver();
@ -187,8 +186,8 @@ const acquireCert = async (domain, acmeOptions, certificateData, certHandler) =>
redis: db.redis,
namespace: 'acme'
});
getLock = util.promisify(lock.waitAcquireLock.bind(lock));
releaseLock = util.promisify(lock.releaseLock.bind(lock));
getLock = (...args) => lock.waitAcquireLock(...args);
releaseLock = (...args) => lock.releaseLock(...args);
}
let lock = await getLock(domainOpLockKey, 10 * 60 * 1000, 3 * 60 * 1000);

View file

@ -84,6 +84,9 @@ module.exports = {
TASK_LOCK_INTERVAL: 1 * 3600 * 1000,
// unlock pending tasks in every 2 minutes
TASK_RELEASE_DELAYED_INTERVAL: 2 * 60 * 1000,
// renewal interval, must be lower than TASK_LOCK_INTERVAL
TASK_UPDATE_INTERVAL: 10 * 60 * 1000,

View file

@ -54,7 +54,7 @@
"html-to-text": "8.0.0",
"humanname": "0.2.2",
"iconv-lite": "0.6.3",
"ioredfour": "1.0.2-ioredis-03",
"ioredfour": "1.1.0-ioredis-05",
"ioredis": "4.27.6",
"ipaddr": "0.1.0",
"ipaddr.js": "2.0.1",

View file

@ -448,25 +448,21 @@ function timer(ttl) {
}
async function runTasks() {
// first release expired tasks
try {
await taskHandler.releasePending();
} catch (err) {
log.error('Tasks', 'Failed releasing expired tasks. error=%s', err.message);
taskTimeout = setTimeout(runTasks, consts.TASK_STARTUP_INTERVAL);
await timer(consts.TASK_STARTUP_INTERVAL);
return runTasks();
}
let pendingCheckTime = 0;
let startTime = Date.now();
let done = false;
log.verbose('Tasks', 'Starting task poll loop');
while (!done) {
if (Date.now() - startTime > 3600 * 1000) {
// Once in a while break the loop, so that pending tasks can be unlocked
done = true;
log.verbose('Tasks', 'Breaking task poll loop');
break;
if (Date.now() - pendingCheckTime > consts.TASK_RELEASE_DELAYED_INTERVAL) {
// Once in a while release pending tasks
try {
await taskHandler.releasePending();
} catch (err) {
log.error('Tasks', 'Failed releasing expired tasks. error=%s', err.message);
await timer(consts.TASK_IDLE_INTERVAL);
} finally {
pendingCheckTime = Date.now();
}
}
try {