From a8796b0bd2799ad3ac67e3dab663c3d4bbb2a3d0 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 12 Sep 2017 12:10:43 +0300 Subject: [PATCH] prevent race condition in getStyles before dbExec.initialized fixes #184 --- background/storage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/background/storage.js b/background/storage.js index c3d30b4a..389dd365 100644 --- a/background/storage.js +++ b/background/storage.js @@ -23,7 +23,8 @@ var cachedStyles = { urlDomains: new Map(), // getDomain() results for 100 last checked urls needTransitionPatch: new Map(), // FF bug workaround mutex: { - inProgress: false, // while getStyles() is reading IndexedDB all subsequent calls + inProgress: true, // while getStyles() is reading IndexedDB all subsequent calls + // (initially 'true' to prevent rogue getStyles before dbExec.initialized) onDone: [], // to getStyles() are queued and resolved when the first one finishes }, }; @@ -92,6 +93,7 @@ dbExec.initialized = false; // (FF may block localStorage depending on its privacy options) do { const done = () => { + cachedStyles.mutex.inProgress = false; getStyles().then(() => { dbExec.initialized = true; window.dispatchEvent(new Event('storageReady'));