Skip to content

Commit 7bd17d9

Browse files
exponential backoff
1 parent e66c295 commit 7bd17d9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/storage/file.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ File.prototype.createWriteStream = function(metadata) {
303303

304304
var numBytesWritten;
305305
var resumableUri;
306-
var RETRY_LIMIT = 3;
306+
var RETRY_LIMIT = 5;
307307
var retries = 0;
308308

309309
// This is used to hold all data coming in from the user's readable stream. If
@@ -510,13 +510,17 @@ File.prototype.createWriteStream = function(metadata) {
510510
return;
511511
}
512512

513-
if (err.code > 499 && err.code < 600 && retries <= RETRY_LIMIT) {
513+
if (err.code > 499 && err.code < 600 && retries < RETRY_LIMIT) {
514+
// Exponential backoff: http://goo.gl/CifIFy
515+
var randomMs = Math.round(Math.random() * 1000);
516+
var waitTime = Math.pow(2, retries) * 1000 + randomMs;
517+
514518
retries++;
515519

516520
// Reset `numBytesWritten` so we update this value by pinging the API.
517521
numBytesWritten = null;
518522

519-
resumeUpload();
523+
setTimeout(resumeUpload, waitTime);
520524
return;
521525
}
522526

0 commit comments

Comments
 (0)