commit 63beb0dd5950c0a2ee0f8afdcc7a4bd756298ff7
parent 6af07e666ee1f8685d246f59c7ef2c26e56a50c2
Author: Jens Stutte <jstutte@mozilla.com>
Date: Wed, 8 Oct 2025 15:06:23 +0000
Bug 1992933 - Normandy.init should register the UI_AVAILABLE_NOTIFICATION only if runAsync. r=nimbus-reviewers,beth
Differential Revision: https://phabricator.services.mozilla.com/D267744
Diffstat:
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/toolkit/components/normandy/Normandy.sys.mjs b/toolkit/components/normandy/Normandy.sys.mjs
@@ -42,9 +42,17 @@ export var Normandy = {
/** Initialization that needs to happen before the first paint on startup. */
async init({ runAsync = true } = {}) {
- // It is important to register the listener for the UI before the first
- // await, to avoid missing it.
- Services.obs.addObserver(this, UI_AVAILABLE_NOTIFICATION);
+ // NOTE: It looks like we can see us being called twice between init(true)
+ // coming from "browser-before-ui-startup" (see BrowserComponents.manifest)
+ // and init(false) coming from FirstStartup.sys.mjs.
+ // We need the UI_AVAILABLE_NOTIFICATION observer only if runAsync == true
+ // and we assume that the rest of the initialization can just happen twice.
+ // TODO: Check which pieces really need to run twice, if any.
+ if (runAsync) {
+ // It is important to register the listener for the UI before the first
+ // await, to avoid missing it.
+ Services.obs.addObserver(this, UI_AVAILABLE_NOTIFICATION);
+ }
// It is important this happens before the first `await`. Note that this
// also happens before migrations are applied.
@@ -64,20 +72,16 @@ export var Normandy = {
this.uiAvailableNotificationObserved.promise,
new Promise(resolve => setTimeout(resolve, 5 * 60 * 1000)),
]);
- }
- // Remove observer for UI notifications. It will error if the notification
- // was already removed, which is fine.
- try {
+ // Remove observer for UI notifications.
Services.obs.removeObserver(this, UI_AVAILABLE_NOTIFICATION);
- } catch (e) {}
+ }
await this.finishInit();
},
async observe(subject, topic) {
if (topic === UI_AVAILABLE_NOTIFICATION) {
- Services.obs.removeObserver(this, UI_AVAILABLE_NOTIFICATION);
this.uiAvailableNotificationObserved.resolve();
}
},