From b4311e08e26861dddc88fbe45f6a81258f0110ed Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 8 Feb 2018 03:06:06 -0500 Subject: [PATCH] Wait for any DB transactions to finish before starting sync purgeDataObjects(), which runs at the beginning of the sync process, uses transactions, and those can fail after the default wait timeout if there's another active transaction. Instead, check explicitly for another transaction and, if there is one, display a nice message and wait for it to finish. This isn't foolproof, but it should reduce the frequency of "operation timed out" sync errors. (Avoiding all long transactions would be a better solution.) (cherry picked from commit bd7e1b222dd690904cf2d9260f8968d5a4e6016f) --- chrome/content/zotero/xpcom/sync/syncRunner.js | 13 +++++++++++++ chrome/locale/en-US/zotero/zotero.properties | 2 ++ 2 files changed, 15 insertions(+) diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 912a3fdc4..da99dd45a 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -139,6 +139,19 @@ Zotero.Sync.Runner_Module = function (options = {}) { this.updateIcons('animate'); + // purgeDataObjects() starts a transaction, so if there's an active one then show a + // nice message and wait until there's not. Another transaction could still start + // before purgeDataObjects() and result in a wait timeout, but this should reduce the + // frequency of that. + while (Zotero.DB.inTransaction()) { + this.setSyncStatus(Zotero.getString('sync.status.waiting')); + Zotero.debug("Transaction in progress -- waiting to sync"); + yield Zotero.DB.waitForTransaction('sync'); + _stopCheck(); + } + + this.setSyncStatus(Zotero.getString('sync.status.preparing')); + // Purge deleted objects so they don't cause sync errors (e.g., long tags) yield Zotero.purgeDataObjects(true); diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 680e10f89..5a6ed254f 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -965,6 +965,8 @@ sync.conflict.chooseThisVersion = Choose this version sync.status.notYetSynced = Not yet synced sync.status.lastSync = Last sync: +sync.status.waiting = Waiting for other operations to finish +sync.status.preparing = Preparing sync sync.status.loggingIn = Logging in to sync server sync.status.gettingUpdatedData = Getting updated data from sync server sync.status.processingUpdatedData = Processing updated data from sync server