commit 32dedc6fb4ae091fdc2c1e863e6a1b643909056c
parent e55177798948da38a9ba69609b4d27928bf3029e
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 9 Jul 2017 23:05:02 -0400
Cancel snapshot saves after 15 seconds
Otherwise a save could go on forever and the connector will never show
an error, and if you quit Zotero the connector will show the
save-to-server dialog (though the connector should have its own
timeout).
Diffstat:
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js
@@ -538,8 +538,7 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
deferred.resolve(201);
} catch(e) {
- Zotero.debug("ERROR");
- Zotero.debug(e);
+ Zotero.debug(e, 1);
deferred.resolve(500);
throw e;
}
diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -30,6 +30,8 @@
* @class Utility functions not made available to translators
*/
Zotero.Utilities.Internal = {
+ SNAPSHOT_SAVE_TIMEOUT: 15000,
+
/**
* Run a function on chunks of a given size of an array's elements.
*
@@ -427,6 +429,7 @@ Zotero.Utilities.Internal = {
| nsIWBP.PERSIST_FLAGS_FORCE_ALLOW_COOKIES
| nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION
| nsIWBP.PERSIST_FLAGS_FROM_CACHE
+ | nsIWBP.PERSIST_FLAGS_CLEANUP_ON_FAILURE
// Mostly ads
| nsIWBP.PERSIST_FLAGS_IGNORE_IFRAMES
| nsIWBP.PERSIST_FLAGS_IGNORE_REDIRECTED_DATA;
@@ -447,9 +450,10 @@ Zotero.Utilities.Internal = {
const wrapColumn = 80;
var deferred = Zotero.Promise.defer();
- wbp.progressListener = new Zotero.WebProgressFinishListener(function () {
+ var listener = new Zotero.WebProgressFinishListener(function () {
deferred.resolve();
});
+ wbp.progressListener = listener;
wbp.saveDocument(
document,
@@ -460,6 +464,18 @@ Zotero.Utilities.Internal = {
wrapColumn
);
+ // Cancel save after timeout has passed, so we return an error to the connector and don't stay
+ // saving forever
+ var timeoutID = setTimeout(function () {
+ if (deferred.promise.isPending()) {
+ Zotero.debug("Stopping save for " + document.location.href, 2);
+ //Zotero.debug(listener.getRequest());
+ deferred.reject("Snapshot save timeout");
+ wbp.cancelSave();
+ }
+ }, this.SNAPSHOT_SAVE_TIMEOUT);
+ deferred.promise.then(() => clearTimeout(timeoutID));
+
return deferred.promise;
},
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -2488,12 +2488,22 @@ Zotero.Browser = new function() {
* Implements nsIWebProgressListener
*/
Zotero.WebProgressFinishListener = function(onFinish) {
+ var _request;
+
+ this.getRequest = function () {
+ return _request;
+ };
+
this.onStateChange = function(wp, req, stateFlags, status) {
//Zotero.debug('onStageChange: ' + stateFlags);
if (stateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP
&& stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK) {
+ _request = null;
onFinish();
}
+ else {
+ _request = req;
+ }
}
this.onProgressChange = function(wp, req, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {