Skip to content

Commit

Permalink
exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Nov 20, 2014
1 parent 162b7dd commit c4c6488
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ File.prototype.createWriteStream = function(metadata) {

var numBytesWritten;
var resumableUri;
var RETRY_LIMIT = 3;
var RETRY_LIMIT = 5;
var retries = 0;

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

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

retries++;

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

resumeUpload();
setTimeout(resumeUpload, waitTime);
return;
}

Expand Down

0 comments on commit c4c6488

Please sign in to comment.