From febc2fcc7d031a4bd96d65be37c86f296c644b39 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 1 May 2023 02:30:37 -0400 Subject: [PATCH] fx-compat: Wait until request completion in WebProgressFinishListener `nsIWebProgressListener.onStateChange()` gets called twice at the end of requests, once with `stateFlags` set to `327696` and once with it set to `262160`, which corresponds to `STATE_STOP + STATE_IS_NETWORK + STATE_IS_REQUEST` and `STATE_STOP + STATE_IS_NETWORK`. httpd.js debug logging shows that the connection is closed between the two calls. In WebProgressFinishListener, we were previously calling `onFinish` after the first one, but in Zotero 7, at least on Linux (or maybe just on slower machines due to a race condition), the file from `saveURI()` doesn't appear to be reliably written after the first call, causing `Attachments.downloadFile()` to fail in `_enforcePDF()` due to an empty file. This changes WebProgressFinishListener to wait until the second `STATE_STOP` call. We'll have to confirm whether this is the state-change pattern for all requests, but it fixes our Find Available PDF tests in CI. --- chrome/content/zotero/xpcom/zotero.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index bd843f2108..9d28121b17 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2003,7 +2003,8 @@ Zotero.WebProgressFinishListener = function(onFinish) { this.onStateChange = function(wp, req, stateFlags, status) { //Zotero.debug('onStateChange: ' + stateFlags); if (stateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP - && stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK) { + && stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK + && !(stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_REQUEST)) { if (_finished) { return; }