Skip to content

fix: crash when a node-integrated iframe is removed before its loop starts - #53833

Merged
MarshallOfSound merged 1 commit into
mainfrom
sam/fix-subframe-uv-handle-teardown
Sep 13, 2026
Merged

MarshallOfSound merged 1 commit into
mainfrom
sam/fix-subframe-uv-handle-teardown

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Fixes #53789.

#52964 gave each nodeIntegrationInSubFrames frame its own NodeBindings, whose dummy_uv_handle_ is only initialized by the task that first runs the frame's loop. A frame removed before that task runs (Meta Pixel's hidden form POST iframes hit this) destroyed a uv_async_t that never went through uv_async_init(), so uv_close() ran on uninitialized memory: a DCHECK in testing builds, heap corruption and an eventual renderer crash in release.

  • UvHandle value-initializes its handle, and reset() frees one that was never initialized (still UV_UNKNOWN_HANDLE) instead of closing it.
  • New spec: the preload removes its own frame from a task queued while the frame's environment is created, which always lands before the loop's first run. It failed 21/21 without the fix (on an older nightly and on current main) and passes 10/10 with it.

Notes: Fixed a renderer crash when an iframe was removed right after loading with nodeIntegrationInSubFrames enabled and sandbox disabled, e.g. on pages that embed Meta Pixel.

@MarshallOfSound MarshallOfSound added semver/patch backwards-compatible bug fixes target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 12, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Sep 12, 2026
…tarts

A nodeIntegrationInSubFrames frame's NodeBindings only initializes its
dummy_uv_handle_ from the task that first runs the frame's loop. A frame
removed before that task ran destroyed a uv_async_t that never went through
uv_async_init(), so uv_close() ran on uninitialized memory.

UvHandle now value-initializes its handle, and reset() frees one that was
never initialized instead of closing it.

Fixes #53789.
@MarshallOfSound
MarshallOfSound force-pushed the sam/fix-subframe-uv-handle-teardown branch from 6b396f4 to 710611a Compare September 12, 2026 00:44
@MarshallOfSound

Copy link
Copy Markdown
Member Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct — I traced the crash path through shell/common/node_bindings.cc and confirmed the fix matches the description: ~NodeBindings() only explicitly resets dummy_uv_handle_ when embed_thread_prepared_ is true (i.e. PrepareEmbedThread() ran and called uv_async_init); when a frame is torn down before that, the member's own destructor still calls reset() on the never-initialized handle. The old code unconditionally called uv_close() there, which is what crashed. Value-initializing the wrapped struct (new T{}) makes an uninitialized handle's type field read as UV_UNKNOWN_HANDLE, and reset() now just deletes in that case instead of calling uv_close().

What was reviewed: the UvHandle constructor/reset changes in shell/common/node_bindings.h, the NodeBindings::~NodeBindings/PrepareEmbedThread interaction in shell/common/node_bindings.cc that the fix depends on, and the other UvHandle<...> call sites (shell/common/api/electron_bindings.h, shell/app/uv_task_runner.cc) to confirm they all init immediately after construction and are unaffected. The new spec test sits inside the existing describe('environments sharing a renderer', ...) block with afterEach(closeAllWindows), so the test window is cleaned up, and it avoids asserting inside the render-process-gone listener, using Promise.race instead.

Extended reasoning...

Overview

The diff is a small, self-contained bug fix in shell/common/node_bindings.h (the UvHandle<T> helper template used to wrap libuv handles) plus a regression test (spec/node-spec.ts) and a tiny preload fixture (spec/fixtures/module/preload-remove-own-frame.js). No public API, docs, or patches are touched.

Security risks

None identified. This is main-process C++ handle-lifecycle bookkeeping around libuv, not reachable from renderer-controlled input, and not part of context-isolation/sandbox/IPC argument validation. The class is a plain heap-new/delete-managed non-GC wrapper (not cppgc-managed), so the Oilpan rules in CLAUDE.md aren't implicated.

Level of scrutiny

This is exactly the kind of small, mechanical, well-tested fix that merits approval: it's a two-branch change to a reset() method with a clear, traceable root cause. I verified the fix's premise directly against NodeBindings::~NodeBindings() and PrepareEmbedThread() in shell/common/node_bindings.cc (lines ~554-567 and ~1095-1121): the explicit dummy_uv_handle_.reset() call is guarded by embed_thread_prepared_, so a frame destroyed before PrepareEmbedThread() first runs leaves the handle to be reset only via the member destructor — which is exactly the path the old uv_close()-always code crashed on. Value-initializing the wrapped struct and branching on UV_UNKNOWN_HANDLE in reset() is a sound, minimal fix, and I checked the other two UvHandle<...> use sites in the repo (shell/common/api/electron_bindings.h, shell/app/uv_task_runner.cc) to confirm they always call the corresponding uv_*_init immediately after construction, so this change doesn't alter their behavior.

Other factors

The new test follows existing conventions in the same file (uses the describe's existing afterEach(closeAllWindows), avoids asserting inside an event listener, uses Promise.race against render-process-gone for a readable failure mode instead of a bare timeout). The PR author states it reproduced the crash 21/21 without the fix and passed 10/10 with it, which is consistent with the race-condition nature of the bug. No CODEOWNERS entries cover the changed files. I could not verify libuv-internal details (e.g. uv_handle_get_type, the numeric value of UV_UNKNOWN_HANDLE) against a synced Chromium/libuv checkout since this appears to be a standalone clone, but these are long-standed, widely documented parts of libuv's public API, and the code's local logic is internally consistent and directly explains the reported crash.

@MarshallOfSound MarshallOfSound removed the new-pr 🌱 PR opened recently label Sep 12, 2026
@MarshallOfSound
MarshallOfSound merged commit b260e07 into main Sep 13, 2026
85 checks passed
@release-clerk

release-clerk Bot commented Sep 13, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a renderer crash when an iframe was removed right after loading with nodeIntegrationInSubFrames enabled and sandbox disabled, e.g. on pages that embed Meta Pixel.

@trop

trop Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "45-x-y", please check out #53883

@trop trop Bot removed the target/45-x-y PR should also be added to the "45-x-y" branch. label Sep 13, 2026
@trop

trop Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #53884

@trop

trop Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #53885

@trop

trop Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #53886

@trop trop Bot added in-flight/42-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y in-flight/44-x-y in-flight/43-x-y in-flight/45-x-y labels Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Pages having Meta Pixel embeded cause renderer-process-gone when sanbox=false + nodeIntegrationInSubFrames=true

2 participants