removed probably race condition on autoexpunge

This commit is contained in:
Andris Reinman 2017-12-13 11:23:18 +02:00
parent dfe94e1e32
commit 384ad224d2
2 changed files with 19 additions and 26 deletions

View file

@ -66,9 +66,9 @@ subject: test6
hello 6
"
mongo "$DBNAME" --eval "db.mailboxes.updateOne({_id: ObjectId('$INBOXID')}, {\$set:{modifyIndex: 5000, uidNext: 1000}})" > /dev/null
mongo "$DBNAME" --eval "db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:1}, {\$set:{modseq: 100}})" > /dev/null
mongo "$DBNAME" --eval "db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:2}, {\$set:{modseq: 5000}})" > /dev/null
mongo "$DBNAME" --eval "db.messages.updateMany({}, {\$inc:{uid: 100}})" > /dev/null
mongo "$DBNAME" --eval "db.mailboxes.updateOne({_id: ObjectId('$INBOXID')}, {\$set:{modifyIndex: 5000, uidNext: 1000}});
db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:1}, {\$set:{modseq: 100}});
db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:2}, {\$set:{modseq: 5000}});
db.messages.updateMany({}, {\$inc:{uid: 100}});" > /dev/null
# curl --silent "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages" | jq

View file

@ -63,15 +63,9 @@ module.exports = server => (mailbox, update, session, callback) => {
};
let query = {
mailbox: mailboxData._id
mailbox
};
if (update.unchangedSince) {
query = {
mailbox: mailboxData._id
};
}
let queryAll = false;
if (update.messages.length !== session.selected.uidList.length) {
// do not use uid selector for 1:*
@ -104,21 +98,6 @@ module.exports = server => (mailbox, update, session, callback) => {
let notifyEntries = [];
let done = (...args) => {
if (shouldExpunge) {
// shcedule EXPUNGE command for current folder
let expungeOptions = {
// create new temporary session so it would not mix with the active one
id: 'auto.' + base32.encode(crypto.randomBytes(10)).toLowerCase(),
user: {
id: session.user.id,
username: session.user.username
}
};
setImmediate(() => {
server.onExpunge(mailbox, { silent: true }, expungeOptions, () => false);
});
}
if (updateEntries.length) {
return db.database.collection('messages').bulkWrite(
updateEntries,
@ -135,6 +114,20 @@ module.exports = server => (mailbox, update, session, callback) => {
// first argument is an error
return callback(...args);
} else {
if (shouldExpunge) {
// shcedule EXPUNGE command for current folder
let expungeOptions = {
// create new temporary session so it would not mix with the active one
id: 'auto.' + base32.encode(crypto.randomBytes(10)).toLowerCase(),
user: {
id: session.user.id,
username: session.user.username
}
};
setImmediate(() => {
server.onExpunge(mailbox, { silent: true }, expungeOptions, () => false);
});
}
updateMailboxFlags(mailboxData, update, () => callback(...args));
}
});