Skip to content

Commit 3eb4b2c

Browse files
committed
no locking for small chunks, add bigger timeframe in that case
1 parent 5196759 commit 3eb4b2c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/attachments/gridstore-storage.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ class GridstoreStorage {
231231
return done();
232232
}
233233

234+
if (attachment.body.length < 255 * 1024) {
235+
// a single chunk attachment, no need for locking
236+
return done();
237+
}
238+
234239
// Try to get a lock
235240
// Using locks is required to prevent multiple messages storing the same large attachment at
236241
// the same time.
@@ -265,8 +270,8 @@ class GridstoreStorage {
265270
return;
266271
}
267272
// most probably a race condition, try again
268-
if (tryCount++ < 5) {
269-
if (/\.chunks /.test(err.message)) {
273+
if (tryCount++ < 20) {
274+
if (/\.chunks /.test(err.message) || err.code === 11000) {
270275
// Partial chunks detected. Might be because of:
271276
// * another process is inserting the same attachment and thus no "files" entry yet (should not happened though due to locking)
272277
// * previously deleted attachment that has not been properly removed
@@ -294,8 +299,8 @@ class GridstoreStorage {
294299

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

0 commit comments

Comments
 (0)