Closed Bug 1946792 Opened 1 month ago Closed 1 month ago

browser created in FxAccountsPairingChannel.sys.mjs needs another strong reference

Categories

(Firefox :: Sync, task)

task

Tracking

()

RESOLVED FIXED
137 Branch
Tracking Status
firefox137 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

https://searchfox.org/mozilla-central/rev/46c5f46a83146b311828b9cdd64b975a08066278/services/fxaccounts/FxAccountsPairingChannel.sys.mjs#29-30

const browser = Services.appShell.createWindowlessBrowser(true);
const {WebSocket} = browser.document.ownerGlobal;

The browser created there is held only by the module global variable.
Once bug 1941472 is fixed, the module globals in system modules behave in the same as the standard ECMAScript modules's globals,
which doesn't necessarily have the same lifetime as the module itself.

Given the browser variable is not closed over by any function, the object pointed by the variable becomes the target of GC after the top-level execution.
While the WebSocket holds the reference to the browser's document's property, it doesn't necessarily keep the global alive, and that results in bug 1946592 issue.

Options:

  • (a) perform browser.document.ownerGlobal inslide FxAccountsPairingChannel's function, so that browser is closed over, so that the browser variable gets the same lifetime as the module itself
  • (b) put browser to FxAccountsPairingChannel's property, so that it gets the same lifetime as FxAccountsPairingChannel, which has the same lifetime as the module given it's exported
Blocks: 1941472

Bug 1941472 is going to change the behavior of module global variables.
The non-exported and not-closed-over global variables doesn't keep the pointed
alive after the top-level script is executed.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

for more context, the other consumers stores the browser reference to the consumer's main object.

https://searchfox.org/mozilla-central/rev/bc00d156c8a5452689cd66cbce30fe10c6594977/toolkit/components/extensions/ExtensionParent.sys.mjs#1430,1458

let windowlessBrowser = Services.appShell.createWindowlessBrowser(true);
...
this._windowlessBrowser = windowlessBrowser;

https://searchfox.org/mozilla-central/rev/bc00d156c8a5452689cd66cbce30fe10c6594977/toolkit/components/thumbnails/BackgroundPageThumbs.sys.mjs#212,248

let wlBrowser = Services.appShell.createWindowlessBrowser(true, flags);
...
this._windowlessContainer = wlBrowser;

https://searchfox.org/mozilla-central/rev/bc00d156c8a5452689cd66cbce30fe10c6594977/toolkit/modules/HiddenFrame.sys.mjs#93-96

this.#browser = Services.appShell.createWindowlessBrowser(
  true,
  chromeFlags
);

One exception is the following, but it doesn't use the browser after the block, so there's no need to keep it alive.

https://searchfox.org/mozilla-central/rev/bc00d156c8a5452689cd66cbce30fe10c6594977/toolkit/components/extensions/parent/ext-downloads.js#1212-1213,1237-1238

let windowlessBrowser =
  Services.appShell.createWindowlessBrowser(true);
...
} finally {
  windowlessBrowser.close();
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/7aaafb5c1e28 Store the windowless browser in the exported object in order to keep it alive. r=markh
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: