commit cc9efde8433b7ec94d4e02878f451b763dab30c6
parent 2b8311d3d7f3da6e7005ee5b14956c4f4aa9da3a
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 16 Jan 2018 11:04:41 -0500
Fix translator architecture hangs on bad JSON in translatorCache
Diffstat:
2 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -744,16 +744,29 @@ Zotero.Schema = new function(){
index[id].extract = true;
}
- let sql = "SELECT metadataJSON FROM translatorCache";
- let dbCache = yield Zotero.DB.columnQueryAsync(sql);
+ let sql = "SELECT fileName, metadataJSON FROM translatorCache";
+ let rows = yield Zotero.DB.queryAsync(sql);
// If there's anything in the cache, see what we actually need to extract
- if (dbCache) {
- for (let i = 0; i < dbCache.length; i++) {
- let metadata = JSON.parse(dbCache[i]);
- let id = metadata.translatorID;
- if (index[id] && index[id].lastUpdated <= metadata.lastUpdated) {
- index[id].extract = false;
- }
+ for (let i = 0; i < rows.length; i++) {
+ let json = rows[i].metadataJSON;
+ let metadata;
+ try {
+ metadata = JSON.parse(json);
+ }
+ catch (e) {
+ Zotero.logError(e);
+ Zotero.debug(json, 1);
+
+ // // If JSON is invalid, clear from cache
+ yield Zotero.DB.queryAsync(
+ "DELETE FROM translatorCache WHERE fileName=?",
+ rows[i].fileName
+ );
+ continue;
+ }
+ let id = metadata.translatorID;
+ if (index[id] && index[id].lastUpdated <= metadata.lastUpdated) {
+ index[id].extract = false;
}
}
diff --git a/chrome/content/zotero/xpcom/translation/translators.js b/chrome/content/zotero/xpcom/translation/translators.js
@@ -116,9 +116,22 @@ Zotero.Translators = new function() {
// Get JSON from cache if possible
if (memCacheJSON || dbCacheEntry) {
- var translator = Zotero.Translators.load(
- memCacheJSON || dbCacheEntry.metadataJSON, path
- );
+ try {
+ var translator = Zotero.Translators.load(
+ memCacheJSON || dbCacheEntry.metadataJSON, path
+ );
+ }
+ catch (e) {
+ Zotero.logError(e);
+ Zotero.debug(memCacheJSON || dbCacheEntry.metadataJSON, 1);
+
+ // If JSON is invalid, clear from cache
+ yield Zotero.DB.queryAsync(
+ "DELETE FROM translatorCache WHERE fileName=?",
+ fileName
+ );
+ continue;
+ }
}
// Otherwise, load from file
else {