Closed Bug 2031444 Opened 7 months ago Closed 7 months ago

CacheEntry pending callbacks form prevent-release cycle at shutdown, leaking nsGlobalWindowInner

Categories

(Core :: Networking: Cache, defect, P3)

defect

Tracking

()

RESOLVED FIXED
151 Branch
Tracking Status
firefox151 --- fixed

People

(Reporter: florian, Assigned: florian)

References

Details

(Whiteboard: [necko-triaged])

Attachments

(1 external file)

CacheEntry stores pending callbacks in its mCallbacks array. Each Callback holds a RefPtr<CacheEntry> mEntry back to the owning entry, forming a prevent-release cycle:

CacheEntry → mCallbacks[i] → Callback.mEntry → CacheEntry

Normally this cycle is broken when the callback fires and is removed from the array. But when an async disk cache read (OPEN_SECRETLY) doesn't complete before process shutdown, the callback is never invoked.

CacheStorageService::Shutdown() clears the global entry tables (under NS_FREE_PERMANENT_DATA), which drops the table's reference to the CacheEntry — but the CacheEntry ↔ Callback cycle keeps both alive. The leaked Callback holds an nsICacheEntryOpenCallback whose JS closure chains through devtools module scopes to a chrome window's global, preventing the nsGlobalWindowInner from being cycle-collected.

Reproduces as a perma-fail on debug builds when running devtools mochitests without the memory-pressure notification (bug 2030904 removes it from the shutdown leak check). For example:

./mach test devtools/client/framework/test/browser_toolbox_options_disable_cache-02.js --headless

The failure message on treeherder is unfortunately not very actionable: TEST-UNEXPECTED-FAIL | leakcheck large nsGlobalWindowInner | devtools/client/framework/test/browser.toml

The fix: clear pending callbacks on all entries during CacheStorageService::Shutdown() before dropping the entry tables, breaking the prevent-release cycle.

Assignee: nobody → florian
Status: NEW → ASSIGNED
Severity: -- → S4
Priority: -- → P3
Whiteboard: [necko-triaged]

I was ready to put up a patch for it, but you beat me :-)

See Also: → 2020133
Pushed by fqueze@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/129f0600463e https://hg.mozilla.org/integration/autoland/rev/9db193a69a05 Clear CacheEntry pending callbacks at shutdown to break prevent-release cycle, r=necko-reviewers,jesup.
Status: ASSIGNED → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → 151 Branch
QA Whiteboard: [qa-triage-done-c152/b151]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: