Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/attachments/gridstore-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ class GridstoreStorage {
return;
}
// most probably a race condition, try again
if (tryCount++ < 5) {
if (/\.chunks /.test(err.message)) {
if (tryCount++ < 20) {
if (err.code === 11000 || /\.chunks /.test(err.message)) {
// Partial chunks detected. Might be because of:
// * another process is inserting the same attachment and thus no "files" entry yet (should not happened though due to locking)
// * previously deleted attachment that has not been properly removed
Expand Down Expand Up @@ -299,18 +299,21 @@ class GridstoreStorage {

// Check how old is the previous chunk
let timestamp = data._id.getTimestamp();
if (timestamp && typeof timestamp.getTime === 'function' && timestamp.getTime() >= Date.now() - 5 * 60 * 1000) {
// chunk is newer than 5 minutes, assume race condition and try again after a while
if (timestamp && typeof timestamp.getTime === 'function' && timestamp.getTime() >= Date.now() - 30 * 60 * 1000) {
// chunk is newer than 30 minutes, assume race condition and try again after a while
return setTimeout(tryStore, 300 + 200 * Math.random());
}

// partial chunks for a probably deleted message detected, try to clean up
setTimeout(() => {
if (returned) {
return;
}
this.cleanupGarbage(id, tryStore);
}, 100 + 200 * Math.random());
setTimeout(
() => {
if (returned) {
return;
}
this.cleanupGarbage(id, tryStore);
},
100 + 200 * Math.random()
);
}
);
} else {
Expand Down