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).
This commit is contained in:
parent
e551777989
commit
32dedc6fb4
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user