Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit f1fffc5

Browse files
authored
Fix double-load of rulesets on update of update channels (#19275)
1 parent 0fad008 commit f1fffc5

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

chromium/background-scripts/background.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,17 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
869869

870870
// Ensure that we check for new rulesets from the update channel immediately.
871871
// If the scope has changed, make sure that the rulesets are re-initialized.
872+
update.removeStorageListener();
872873
store.set({update_channels: item.update_channels}, () => {
873-
// Since loadUpdateChannesKeys is already contained in chrome.storage.onChanged
874-
// within update.js, the below call will make it run twice. This is
875-
// necesssary to avoid a race condition, see #16673
876874
update.loadUpdateChannelsKeys().then(() => {
877875
update.resetTimer();
878876
if(scope_changed) {
879877
initializeAllRules();
880878
}
881879
sendResponse(true);
882880
});
881+
update.addStorageListener();
883882
});
884-
885883
});
886884
return true;
887885
},

chromium/background-scripts/update.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async function performCheck() {
252252
}
253253
};
254254

255-
chrome.storage.onChanged.addListener(async function(changes, areaName) {
255+
async function storageListener(changes, areaName) {
256256
if (areaName === 'sync' || areaName === 'local') {
257257
if ('autoUpdateRulesets' in changes) {
258258
if (changes.autoUpdateRulesets.newValue) {
@@ -266,7 +266,17 @@ chrome.storage.onChanged.addListener(async function(changes, areaName) {
266266
if ('update_channels' in changes) {
267267
await loadUpdateChannelsKeys();
268268
}
269-
});
269+
};
270+
271+
function addStorageListener() {
272+
chrome.storage.onChanged.addListener(storageListener);
273+
}
274+
275+
function removeStorageListener() {
276+
chrome.storage.onChanged.removeListener(storageListener);
277+
}
278+
279+
addStorageListener();
270280

271281
let initialCheck,
272282
subsequentChecks;
@@ -326,7 +336,9 @@ Object.assign(exports, {
326336
initialize,
327337
getRulesetTimestamps,
328338
resetTimer,
329-
loadUpdateChannelsKeys
339+
loadUpdateChannelsKeys,
340+
addStorageListener,
341+
removeStorageListener,
330342
});
331343

332344
})(typeof exports == 'undefined' ? require.scopes.update = {} : exports);

0 commit comments

Comments
 (0)