Cancel deleting expired messages when it takes too long

This commit is contained in:
Andris Reinman 2017-06-05 19:41:21 +03:00
parent 61347a5c9e
commit e5d739d84f

24
imap.js
View file

@ -1968,9 +1968,10 @@ function deleteOrphanedAttachments(callback) {
function clearExpiredMessages() {
clearTimeout(gcTimeout);
let startTime = Date.now();
// First, acquire the lock. This prevents multiple connected clients for deleting the same messages
gcLock.acquireLock('gc_expired', 3 * 60 * 60 * 1000 /* Lock expires after 61min if not released */, (err, lock) => {
gcLock.acquireLock('gc_expired', 3 * 60 * 60 * 1000 /* Lock expires after 3 hours if not released */, (err, lock) => {
if (err) {
server.logger.error(
{
@ -2024,13 +2025,8 @@ function clearExpiredMessages() {
});
let deleted = 0;
let processNext = () => {
cursor.next((err, message) => {
if (err) {
return done(err);
}
if (!message) {
return cursor.close(() => {
let clear = () =>
cursor.close(() => {
// delete all attachments that do not have any active links to message objects
deleteOrphanedAttachments(() => {
server.logger.debug(
@ -2043,6 +2039,18 @@ function clearExpiredMessages() {
done(null, true);
});
});
let processNext = () => {
if (Date.now() - startTime > GC_INTERVAL * 0.8) {
return clear();
}
cursor.next((err, message) => {
if (err) {
return done(err);
}
if (!message) {
return clear();
}
server.logger.info(