diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js index 65cc79d06..4483ecec0 100644 --- a/chrome/content/zotero/xpcom/storage/zfs.js +++ b/chrome/content/zotero/xpcom/storage/zfs.js @@ -34,7 +34,8 @@ Zotero.Sync.Storage.Mode.ZFS = function (options) { this._s3Backoff = 1; this._s3ConsecutiveFailures = 0; this._maxS3Backoff = 60; - this._maxS3ConsecutiveFailures = 5; + this._maxS3ConsecutiveFailures = options.maxS3ConsecutiveFailures !== undefined + ? options.maxS3ConsecutiveFailures : 5; }; Zotero.Sync.Storage.Mode.ZFS.prototype = { mode: "zfs", @@ -157,7 +158,7 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = { // If S3 connection is interrupted, delay and retry, or bail if too many // consecutive failures if (status == 0 || status == 500 || status == 503) { - if (this._s3ConsecutiveFailures < this._maxS3ConsecutiveFailures) { + if (++this._s3ConsecutiveFailures < this._maxS3ConsecutiveFailures) { let libraryKey = item.libraryKey; let msg = "S3 returned 0 for " + libraryKey + " -- retrying download" Components.utils.reportError(msg); @@ -165,13 +166,12 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = { if (this._s3Backoff < this._maxS3Backoff) { this._s3Backoff *= 2; } - this._s3ConsecutiveFailures++; Zotero.debug("Delaying " + libraryKey + " download for " + this._s3Backoff + " seconds", 2); Zotero.Promise.delay(this._s3Backoff * 1000) .then(function () { - deferred.resolve(this._downloadFile(request)); - }); + deferred.resolve(this.downloadFile(request)); + }.bind(this)); return; } diff --git a/test/tests/zfsTest.js b/test/tests/zfsTest.js index 41a680bcc..70bf7db7b 100644 --- a/test/tests/zfsTest.js +++ b/test/tests/zfsTest.js @@ -90,7 +90,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () { var engine = new Zotero.Sync.Storage.Engine({ libraryID: options.libraryID || Zotero.Libraries.userLibraryID, controller: new Zotero.Sync.Storage.Mode.ZFS({ - apiClient: client + apiClient: client, + maxS3ConsecutiveFailures: 2 }), stopOnError: true });