-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition between uBlock / Chromium policies #1608
Comments
FWIW I'm experimenting with a patch that registers a listener and runs |
Update: these changes work like a charm; I'm going to look for a more appropriate home for them then open a PR :) |
Here is the PR; I was not able to open it against the upstream repo as I've not previously contributed mightyapp/uBlock#1 |
Sounds like this might be related to #1547. I can't accept the PR, using Best is to identify whether there is an actual issue with uBO or the browser, and fix this in uBO, or ask the browser devs to fix it on their side if the issue is browser-side. |
If it's related to #1547, then I suspect merely forcing a restart without listening to storage changes is what work. If so, then it's possible to come up with forcing uBO to restart when it detects it's a first run condition, which occurs only at install time. |
Could you try the following changes? This will force a reload at the end of the initialization sequence when uBO detects it's a first run, and that the browser is Chromium-based. diff --git a/src/js/start.js b/src/js/start.js
index 63285e588..026aa0809 100644
--- a/src/js/start.js
+++ b/src/js/start.js
@@ -111,11 +111,11 @@ const onVersionReady = function(lastVersion) {
µb.redirectEngine.invalidateResourcesSelfie();
const lastVersionInt = vAPI.app.intFromVersion(lastVersion);
- if ( lastVersionInt === 0 ) { return; }
// https://github.com/LiCybora/NanoDefenderFirefox/issues/196
// Toggle on the blocking of CSP reports by default for Firefox.
if (
+ lastVersionInt !== 0 &&
vAPI.webextFlavor.soup.has('firefox') &&
lastVersionInt <= 1031003011
) {
@@ -332,7 +332,7 @@ try {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
// Wait for onCacheSettingsReady() to be fully ready.
- await Promise.all([
+ const [ , , lastVersion ] = await Promise.all([
µb.loadSelectedFilterLists().then(( ) => {
log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`);
}),
@@ -345,6 +345,7 @@ try {
vAPI.storage.get(createDefaultProps()).then(fetched => {
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
onFirstFetchReady(fetched, adminExtra);
+ return fetched.version;
}),
µb.loadUserSettings().then(fetched => {
log.info(`User settings ready ${Date.now()-vAPI.T0} ms after launch`);
@@ -354,6 +355,13 @@ try {
log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`);
}),
]);
+
+ // https://github.com/uBlockOrigin/uBlock-issues/issues/1547
+ if ( lastVersion === '0.0.0.0' && vAPI.webextFlavor.soup.has('chromium') ) {
+ vAPI.app.restart();
+ return;
+ }
+
} catch (ex) {
console.trace(ex);
} If this does not work, at least we could merge with your |
Thanks @gorhill! I like how your code targets Chromium specifically, thanks for sharing how you do that 😄 While I'm reasonably confident restarting like you propose will work,do you expect the perf hit to "only" be 1 additional MB, and only when uBO is either loading or the user is changing uBO settings? I wonder if that's an acceptable tradeoff; for example in my case the additional MB is negligible (especially if it's released shortly after), and the One challenge with installing the listener after a first-install run (vs. at the top of the file, like I did) is that the underlying storage may have already changed. I guess we could do a comparison against the last-fetched admin settings as well, but there we are consuming memory again! Please let me know what you think and I'll be sure to ship the changes :) [1] See @ghost's comment and @vtknightmare's description on the original issue |
I meant to write "MBs", a memory snapshot will be many MBs. Example of performance issue related to the use of So I rather avoid having to subscribe a listener which is meant for all storages just for the sake of listening to the As for hot-swapping managed settings, can you also force a reload of extensions through policies once the settings have changed? |
Oh gosh, yes copying the bigdict every time uBO updates
I don't think such a mechanism exists by policies, but I'll look into resetting using I'll try applying your diff shortly! |
Your diff (also in the above PR) works great! And |
If I understand correctly, you can use |
Close enough—in our case we deploy the browser with some extensions we force-install by policy; one of those extensions declares the I hope this discussion helps any future travelers! @gorhill, is there anything else I can do to help get this merged? |
Related issue: - uBlockOrigin/uBlock-issues#1547 The approach used to fix the issue was confirmed working in the following related issue: - uBlockOrigin/uBlock-issues#1608 (comment)
I have committed the change to force-restart at first install in order to take care of #1547 (thanks for feedback confirming this worked), though in your specific scenario this does not take care of "hotswapping" managed settings, for this your other solution is the only one which works. |
Prerequisites
Description
I'm managing a uBlock deployment where we need to update the policy on each deploy because the extension ID is not guaranteed to be consistent between deploys. After we update the policy, we restart Chromium, so we know the extension is running its
js/start
after the policy file has been written.Meanwhile, uBlock does not consistently apply the policy's settings. I suspect there is a race condition somewhere, where e.g. Chromium does not guarantee
chrome.storage.managed
has loaded all its policy files before extensions start to load.I suspect the
chrome.storage.onChanged.addListener
API could help fix this easily, and also let deployment admins hot-swap policies as necessary. For example, runningµBlock.restoreAdminSettings().then(µBlock.loadSelectedFilterLists)
seems to work, although I bet we'd want to adopt some otherjs/start
callbacks too.A specific URL where the issue occurs
N/A, but here's a Loom: https://www.loom.com/share/55aa104db8d649f1aa622b137ed01cfa
Steps to Reproduce
/etc/chromium/policies/managed/ublock_policy.json
Expected behavior:
I expected the policy to be consistently applied in Step 4, and hoped it would have been applied in Step 2
Actual behavior:
The policy was inconsistently applied (today 2/3 times; on Friday's testing 1/4 times) in Step 4, and is never applied in Step 2
Your environment
The text was updated successfully, but these errors were encountered: