The default bug view has changed. See this FAQ.

SDK is leaking on require("context-menu").Item({label:"foo"});

RESOLVED FIXED in 1.10

Status

Add-on SDK
General
P2
normal
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: ochameau, Assigned: ochameau)

Tracking

unspecified
1.10
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [MemShrink:P2])

Attachments

(1 attachment)

(Assignee)

Description

5 years ago
Yet another leak has been identified on context-menu on addon disabling.
We are leaking all modules when a module is using `Item` class from context-menu.

  var cm = require("context-menu");
  cm.Item({
    label: "Go to Resolved Link"
  });

I'm checking only on master, the leak may be different with older SDK version.
Whiteboard: [MemShrink]
So web content never leaks here -- the issue is that, if the add-on uses a context-menu item, the add-on's modules will stick around even after the add-on is disabled?
(Assignee)

Comment 2

5 years ago
(In reply to Justin Lebar [:jlebar] from comment #1)
> So web content never leaks here -- the issue is that, if the add-on uses a
> context-menu item, the add-on's modules will stick around even after the
> add-on is disabled?

Yes, that's exactly it.
(Assignee)

Comment 3

5 years ago
A first improvement could be to avoid leaking all modules, but only context-menu related ones. See bug 764866.
Can we test on stabilization and see if it occurs there too?
Priority: -- → P2
Assignee: nobody → poirot.alex
Whiteboard: [MemShrink] → [MemShrink:P2]
(Assignee)

Comment 5

5 years ago
Created attachment 638414 [details]
Pull request 475

This leak is due to some leak in content-proxy.js.

We are leaking JS proxies between the time we are destroying the content script and the time of the destruction of the content document.
When the related content document is destroyed, we free everything.
So that if you close all tabs opened when the addon was active (including about:addons!), we do not leak addons compartments.

In most cases, we destroy the content script when the related document is destroyed. But not in case of addon disabling ... So it is worth fixing this.

The fix itself is quite easy. Instead of storing the JS proxy on the xraywrapper itself, we use a WeakMap.
Attachment #638414 - Flags: review?(rFobic)
Attachment #638414 - Flags: review?(rFobic) → review+

Comment 6

5 years ago
Commits pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/7482b9b05283e594b6763beda520839a005f816a
Bug 764831: Avoid leaking JS proxies on addon disabling.

https://github.com/mozilla/addon-sdk/commit/983a9efe8ea2decc1f1e594799f4c0eaea5b1efb
Merge pull request #475 from ochameau/bug/764831-avoid-leaking-js-proxies

Bug 764831: Avoid leaking JS proxies on addon disabling. r=@gozala
(Assignee)

Comment 7

5 years ago
It would be cool to get this fix pushed into stabilization. It isn't a severe leak as related objects are freed whent the tab is closed, but it may help investigate on more important leaks if we aren't hitting this one at first place.
(Assignee)

Updated

5 years ago
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.10
Depends on: 781619
(Assignee)

Comment 8

5 years ago
Reverted per bug 781619 comment 11:
  https://github.com/mozilla/addon-sdk/commit/f3d13138dd1264a7efa507e7726ac9f1d9137f5a
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Cherry-picked to stabilization: 
https://github.com/mozilla/addon-sdk/commit/e2143125df0845b7e72cac5167d300a5ef406cbf

Updated

5 years ago
Depends on: 784116
(Assignee)

Comment 10

5 years ago
It appears to be a bit more harmfull than what I was thinking.
In case of page-mod, when we apply a content script on an iframe and access to  `window.parent`, we end up leaking iframe's content script until the parent document is destroyed.
So that, in bug 780391, wallflower addon is leaking all ecmascript test iframes until we close ecmascript tab.

That's because we cache JS proxies on the xraywrapper itself. The proxy and its sandbox are kept alive until the related xray is destroyed. In case of window.parent and any cross compartment usages, it ends up being quite bad behavior!

With Weakmap patch, wallflower isn't leaking. But Weakmap doesn't work on all kind of wrappers, so that the cache may loose some proxies. But from what I know it is the only way to avoid leaking here.
(Assignee)

Comment 11

5 years ago
I tried to use Components.utils.getWeakReference without much success, it still leaks when trying to access window.parent while running ecmascript tests.

I'm not able to come up with any ideal fix. We either leak or miss some proxies instances from cache. Missing proxies from cache means that for the same webpage object, we will generate two distinct objects which will have different set of expendos.
From what I can see, here is the kind of object that can't be used in weakmaps: Storage, Events, Location, XPath objects, ImageData, ...
As Andrew said in bug 761620 comment 0, it works only for node wrappers.

When bug 761620 will land, we will be able to detect cases where weakmap fails to use the key and switch back to safe-leaky way of doing. But in the meantime I don't know exactly how to address this.
(Assignee)

Updated

5 years ago
Duplicate of this bug: 779224
(Assignee)

Updated

5 years ago
Blocks: 780391
Depends on: 788324
(Assignee)

Comment 13

5 years ago
Actually this bug can be considered as fixed, thanks to bug 786976, and the removal of JS proxies.
And even if the original report mentioned context-menu, this leak was'nt related to context-menu, but worker code and all dependent APIs.
Status: REOPENED → RESOLVED
Last Resolved: 5 years ago5 years ago
No longer depends on: 788324
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.