Closed Bug 1317867 Opened 8 years ago Closed 8 years ago

Intermittent devtools/client/netmonitor/test/browser_net_footer-summary.js | leaked 2 window(s) until shutdown [url = about:devtools-toolbox]

Categories

(DevTools :: Netmonitor, defect, P3)

defect

Tracking

(firefox51 unaffected, firefox52 unaffected, firefox53 fixed)

RESOLVED FIXED
Firefox 53
Tracking Status
firefox51 --- unaffected
firefox52 --- unaffected
firefox53 --- fixed

People

(Reporter: intermittent-bug-filer, Assigned: jsnajdr)

Details

(Keywords: intermittent-failure)

Attachments

(1 file)

How the leak happens:

1. The test require()'s the selectors module and uses it. It doesn't use the module already loaded in the Netmonitor window, but loads its own instance in its own loader.

2. The selectors module contains memoized selectors, i.e., the last returned value is remembered inside the selector.

3. The memoized value keeps a reference to the Netmonitor window. More precisely, the value object contains a function, that function has a closure, and that closure (aka lexical environment) contains the window global.

4. After the test is finished, it checks for window and docshell leaks. At that time, the test tab is closed, the toolbox is closed, too, so all its DOM windows should be gone.

5. But the selectors module is still present in the test loader, so the references to DOM windows still exist - leak detected!

How to solve this?

Keep a strict distinction between the application code we are testing, and the test code that does the testing. Don't load application modules into the test loader, but use the application loader instead.

I'm attaching a patch that fixed the only leak that's happening so far, but we should fix several other tests that aren't leaking yet:

- many tests are using the L10N module. Don't load a new instance into the test, but use the already existing instance owned by the application.
- as more and more parts are converted to Redux, the tests use the modules for actions and selectors, so that they can trigger actions and inspect the application state. All these modules should be accessed using the application loader. No separate instances in the test loader.
Assignee: nobody → jsnajdr
Comment on attachment 8812120 [details]
Bug 1317867 - Fixed window leak in browser_net_footer-summary.js mochitest

https://reviewboard.mozilla.org/r/94006/#review94162

Very nice!

Thanks for detailed explanation, you could also put
a comment directly into the test file.

Honza
Attachment #8812120 - Flags: review?(odvarko) → review+
(In reply to Jan Honza Odvarko [:Honza] from comment #5)
> Thanks for detailed explanation, you could also put
> a comment directly into the test file.

Eventually, every mochitest should use winRequire like this one. Should we explain it everywhere? It's not a one-off exception.
Pushed by jsnajdr@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/7d0345ea4344
Fixed window leak in browser_net_footer-summary.js mochitest r=Honza
(In reply to Jarda Snajdr [:jsnajdr] from comment #6)
> (In reply to Jan Honza Odvarko [:Honza] from comment #5)
> > Thanks for detailed explanation, you could also put
> > a comment directly into the test file.
> 
> Eventually, every mochitest should use winRequire like this one. Should we
> explain it everywhere? It's not a one-off exception.
Yeah I know. It doesn't make much sense to repeat the same comment in every test, but
it would be good to have it somewhere. Perhaps a new mochitest-tips.md file?

Honza


Honza
https://hg.mozilla.org/mozilla-central/rev/7d0345ea4344
Status: NEW → RESOLVED
Closed: 8 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → Firefox 53
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: