Update WebDAV request timeouts for HTTP.request() auto 5xx retry

This commit is contained in:
Dan Stillman 2019-05-26 06:37:19 -04:00
parent dc60e5f840
commit 25e34b7b99
2 changed files with 47 additions and 10 deletions

View file

@ -42,6 +42,9 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
mode: "webdav", mode: "webdav",
name: "WebDAV", name: "WebDAV",
ERROR_DELAY_INTERVALS: [2500],
ERROR_DELAY_MAX: 3000,
get verified() { get verified() {
return Zotero.Prefs.get("sync.storage.verified"); return Zotero.Prefs.get("sync.storage.verified");
}, },
@ -223,7 +226,14 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
Zotero.debug("Caching WebDAV credentials"); Zotero.debug("Caching WebDAV credentials");
try { try {
var req = yield Zotero.HTTP.request("OPTIONS", this.rootURI); var req = yield Zotero.HTTP.request(
"OPTIONS",
this.rootURI,
{
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
}
);
Zotero.debug("WebDAV credentials cached"); Zotero.debug("WebDAV credentials cached");
this._cachedCredentials = true; this._cachedCredentials = true;
@ -504,6 +514,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
{ {
successCodes: [200, 204, 404], successCodes: [200, 204, 404],
requestObserver: xmlhttp => request.setChannel(xmlhttp.channel), requestObserver: xmlhttp => request.setChannel(xmlhttp.channel),
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
debug: true debug: true
} }
); );
@ -544,6 +556,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
} }
}); });
}, },
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
debug: true debug: true
} }
); );
@ -607,6 +621,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
options.onRequest(req); options.onRequest(req);
} }
}, },
errorDelayMax: 0,
debug: true debug: true
} }
); );
@ -634,6 +649,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
headers: Object.assign({}, headers, contentTypeXML), headers: Object.assign({}, headers, contentTypeXML),
successCodes: [207, 404], successCodes: [207, 404],
requestObserver, requestObserver,
errorDelayMax: 0,
debug: true debug: true
}); });
@ -649,6 +665,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
successCodes: [404], successCodes: [404],
responseType: 'text', responseType: 'text',
requestObserver, requestObserver,
errorDelayMax: 0,
debug: true debug: true
} }
) )
@ -669,6 +686,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
body: " ", body: " ",
successCodes: [200, 201, 204], successCodes: [200, 201, 204],
requestObserver, requestObserver,
errorDelayMax: 0,
debug: true debug: true
}); });
@ -679,6 +697,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
successCodes: [200, 404], successCodes: [200, 404],
responseType: 'text', responseType: 'text',
requestObserver, requestObserver,
errorDelayMax: 0,
debug: true debug: true
} }
); );
@ -691,6 +710,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
{ {
successCodes: [200, 204], successCodes: [200, 204],
requestObserver, requestObserver,
errorDelayMax: 0,
debug: true debug: true
} }
); );
@ -717,7 +737,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
headers: Object.assign({}, headers, contentTypeXML), headers: Object.assign({}, headers, contentTypeXML),
body: xmlstr, body: xmlstr,
requestObserver, requestObserver,
successCodes: [207, 404] successCodes: [207, 404],
errorDelayMax: 0
}); });
if (req.status == 207) { if (req.status == 207) {
@ -742,9 +763,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
var promptService = var promptService =
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
createInstance(Components.interfaces.nsIPromptService); createInstance(Components.interfaces.nsIPromptService);
var uri = err.uri; if (err.url) {
if (uri) { var spec = err.url.scheme + '://' + err.url.hostPort + err.url.path;
var spec = uri.scheme + '://' + uri.hostPort + uri.path;
} }
var errorTitle, errorMsg; var errorTitle, errorMsg;
@ -752,7 +772,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
if (err instanceof Zotero.HTTP.UnexpectedStatusException) { if (err instanceof Zotero.HTTP.UnexpectedStatusException) {
switch (err.status) { switch (err.status) {
case 0: case 0:
errorMsg = Zotero.getString('sync.storage.error.serverCouldNotBeReached', err.channel.URI.host); errorMsg = Zotero.getString('sync.storage.error.serverCouldNotBeReached', err.url.host);
break; break;
case 401: case 401:
@ -985,6 +1005,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
body: xmlstr, body: xmlstr,
headers: Object.assign({ Depth: 1 }, contentTypeXML), headers: Object.assign({ Depth: 1 }, contentTypeXML),
successCodes: [207], successCodes: [207],
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
debug: true debug: true
} }
); );
@ -1113,6 +1135,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
responseType: 'text', responseType: 'text',
requestObserver: xmlhttp => request.setChannel(xmlhttp.channel), requestObserver: xmlhttp => request.setChannel(xmlhttp.channel),
dontCache: true, dontCache: true,
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
debug: true debug: true
} }
); );
@ -1224,6 +1248,8 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
}, },
body: xmlstr, body: xmlstr,
successCodes: [200, 201, 204], successCodes: [200, 201, 204],
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
debug: true debug: true
} }
) )
@ -1293,7 +1319,9 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
"MKCOL", "MKCOL",
this.rootURI, this.rootURI,
{ {
successCodes: [201] successCodes: [201],
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
} }
); );
}, },
@ -1388,7 +1416,9 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
"DELETE", "DELETE",
deleteURI, deleteURI,
{ {
successCodes: [200, 204, 404] successCodes: [200, 204, 404],
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
} }
); );
} }
@ -1424,7 +1454,9 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
"DELETE", "DELETE",
deletePropURI, deletePropURI,
{ {
successCodes: [200, 204, 404] successCodes: [200, 204, 404],
errorDelayIntervals: this.ERROR_DELAY_INTERVALS,
errorDelayMax: this.ERROR_DELAY_MAX,
} }
); );
switch (req.status) { switch (req.status) {

View file

@ -64,6 +64,8 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () {
Zotero.Sync.Storage.Local.setModeForLibrary(Zotero.Libraries.userLibraryID, 'webdav'); Zotero.Sync.Storage.Local.setModeForLibrary(Zotero.Libraries.userLibraryID, 'webdav');
controller = new Zotero.Sync.Storage.Mode.WebDAV; controller = new Zotero.Sync.Storage.Mode.WebDAV;
controller.ERROR_DELAY_INTERVALS = [1];
controller.ERROR_DELAY_MAX = [5];
Zotero.Prefs.set("sync.storage.scheme", davScheme); Zotero.Prefs.set("sync.storage.scheme", davScheme);
Zotero.Prefs.set("sync.storage.url", davHostPath); Zotero.Prefs.set("sync.storage.url", davHostPath);
Zotero.Prefs.set("sync.storage.username", davUsername); Zotero.Prefs.set("sync.storage.username", davUsername);
@ -224,7 +226,10 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () {
Zotero.getString('sync.storage.error.webdav.requestError', [500, "GET"]) Zotero.getString('sync.storage.error.webdav.requestError', [500, "GET"])
); );
assertRequestCount(1); assert.isAbove(
server.requests.filter(r => r.responseHeaders["Fake-Server-Match"]).length - requestCount,
1
);
assert.isTrue(library.storageDownloadNeeded); assert.isTrue(library.storageDownloadNeeded);
assert.equal(library.storageVersion, 0); assert.equal(library.storageVersion, 0);