File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff 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 ( / \. c h u n k s / . test ( err . message ) ) {
273+ if ( tryCount ++ < 20 ) {
274+ if ( / \. c h u n k s / . 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
You can’t perform that action at this time.
0 commit comments