Skip to content

Conversation

@FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Jan 9, 2026

To drastically reduce the amount of memory leaked if the iframe cannot be garbage collected properly, this PR modifies terminateJob to navigate the iframe away from the Snaps execution environment before removing it, effectively unloading it.

Before:

Explicit Allocations

15.36 MB (100.0%) -- explicit
└──15.36 MB (100.0%) -- window-objects/top(none)/detached
   ├──15.26 MB (99.40%) -- window(http://localhost:6363/)
   │  ├───7.67 MB (49.97%) ++ js-realm(moz-nullprincipal:{45eed705-e0da-4e2b-b0bf-e7ac336c93f4}?http://localhost:6363, http://localhost:6363/)
   │  ├───5.76 MB (37.49%) ++ js-realm(moz-nullprincipal:{8cb3b86e-774f-4a1a-bf6a-eeac2636fe9f}?http://localhost:6363, http://localhost:6363/)
   │  ├───1.83 MB (11.94%) ++ dom
   │  └───0.00 MB (00.00%) ++ (2 tiny)
   └───0.09 MB (00.60%) ++ window(chrome://devtools/content/shared/webextension-fallback.html#webextension-flask@metamask.io)

After:

Explicit Allocations

0.14 MB (100.0%) -- explicit
└──0.14 MB (100.0%) -- window-objects/top(none)/detached/window(about:blank)
   ├──0.06 MB (46.17%) ++ js-realm(moz-nullprincipal:{0114dc8e-3f5e-4a2c-8008-c4219c84dcc0}?moz-extension://1465affa-73bf-4b77-9103-8afb21b2fa9d, about:blank)
   ├──0.06 MB (46.17%) ++ js-realm(moz-nullprincipal:{7e2fd14e-3040-493d-862a-9c207eae5213}?moz-extension://1465affa-73bf-4b77-9103-8afb21b2fa9d, about:blank)
   ├──0.01 MB (07.16%) ++ dom
   └──0.00 MB (00.50%) ++ (2 tiny)

Note

Improves termination flow and reduces iframe memory retention by making job termination asynchronous and explicitly unloading iframes before removal.

  • Changes AbstractExecutionService.terminateJob to return a Promise<void> and awaits it in terminateSnap and when init times out in #initStreams
  • In IframeExecutionService, terminateJob now navigates the iframe to about:blank (with a short withTimeout-guarded wait for load) before removing it
  • Updates NodeProcessExecutionService and WebViewExecutionService terminateJob implementations to async (no functional change beyond signature)

Written by Cursor Bugbot for commit c5ec278. This will update automatically on new commits. Configure here.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.33%. Comparing base (6653139) to head (c5ec278).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...lers/src/services/iframe/IframeExecutionService.ts 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3796      +/-   ##
==========================================
- Coverage   98.34%   98.33%   -0.01%     
==========================================
  Files         422      422              
  Lines       12059    12067       +8     
  Branches     1872     1873       +1     
==========================================
+ Hits        11859    11866       +7     
- Misses        200      201       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrederikBolding FrederikBolding marked this pull request as ready for review January 9, 2026 13:49
@FrederikBolding FrederikBolding requested a review from a team as a code owner January 9, 2026 13:49
@FrederikBolding FrederikBolding added this pull request to the merge queue Jan 9, 2026
Merged via the queue into main with commit a37a59f Jan 9, 2026
124 of 126 checks passed
@FrederikBolding FrederikBolding deleted the fb/memory-leak branch January 9, 2026 14:34
@naugtur
Copy link

naugtur commented Jan 9, 2026

certified good-enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants