diff --git a/imap.js b/imap.js index 148bfcce..0f0a771f 100644 --- a/imap.js +++ b/imap.js @@ -1003,12 +1003,16 @@ server.onCopy = function (path, update, session, callback) { uidNext: true }, (err, item) => { if (err) { - return updateQuota(() => callback(err)); + return cursor.close(() => { + updateQuota(() => callback(err)); + }); } if (!item || !item.value) { // was not able to acquire a lock - return updateQuota(() => callback(null, 'TRYCREATE')); + return cursor.close(() => { + updateQuota(() => callback(null, 'TRYCREATE')); + }); } let uidNext = item.value.uidNext; @@ -1029,7 +1033,9 @@ server.onCopy = function (path, update, session, callback) { db.database.collection('messages').insertOne(message, err => { if (err) { - return updateQuota(() => callback(err)); + return cursor.close(() => { + updateQuota(() => callback(err)); + }); } copiedMessages++; diff --git a/lib/message-handler.js b/lib/message-handler.js index 18f6b7be..d4ddf8ce 100644 --- a/lib/message-handler.js +++ b/lib/message-handler.js @@ -611,11 +611,11 @@ class MessageHandler { uidNext: true }, (err, item) => { if (err) { - return done(err); + return cursor.close(() => done(err)); } if (!item || !item.value) { - return done(new Error('Mailbox disappeared')); + return cursor.close(() => done(new Error('Mailbox disappeared'))); } let uidNext = item.value.uidNext; @@ -647,7 +647,7 @@ class MessageHandler { _id: message._id }, updateOptions, err => { if (err) { - return done(err); + return cursor.close(() => done(err)); } if (options.session) {