Repository navigation
fix: illegal access errors when a same-process child window or subframe closes - #53042
Merged
Merged
Conversation
…me closes (#52964) * fix: give each renderer Node.js environment its own uv loop Same-process child windows and node-integrated subframes each get a Node.js environment, and until now all of them shared uv_default_loop() on the renderer main thread. Freeing one (FreeEnvironment runs the loop until that environment's handles close, with JavaScript disallowed on the isolate) therefore dispatched the other environments' pending immediates, timers, fs and threadpool callbacks in that window, which threw "Uncaught illegal access" in the surviving page or aborted the renderer (InternalCallbackScope / ToLocalChecked checks). NodeBindings can now integrate a given loop or own a fresh one (as the worker path already did), and the renderer keeps one NodeBindings + ElectronBindings pair per frame environment: the first borrows the process-lifetime uv_default_loop() integration so native modules that use the default loop keep working, later ones own their loop. Tearing an environment down parks that loop's embed thread and frees it without touching anyone else's handles. This also replaces the uv_env hand-off between main-frame environments and the injected-frames bookkeeping with a RenderFrame-keyed map, and gives each new environment its first loop run from a fresh task since child contexts can be created from inside a script. Fixes #36858 Fixes #40607 * fix: don't stack an error message listener per renderer environment CreateEnvironment adds Electron's V8 message listener for renderer and worker environments, and V8 keeps every listener it is given, so each navigation or child frame added another copy and uncaught errors ran the async-hook cleanup once per environment ever created on the isolate. Remove the previous registration before adding. Also restate why about:blank subframes are skipped for Node.js integration: freeing their environment is no longer a problem, but they commit synchronously in the renderer and so never receive the preload startup data the sandboxed bundle needs. * test: cover child-window loops, opener reloads and napi work across renderer environments Adds an async export to the echo fixture (a libuv threadpool round trip that calls back into JS, the napi path that aborted in InternalCallbackScope when it completed under another environment's context) and uses it to check that same-process child windows, including a synchronously created about:blank one, run immediates, fs and napi work on their own loop, that a child keeps working while its opener reloads, and that the survivor's napi callbacks still arrive when a sibling environment is freed. * test: cover napi thread-safe functions in child window environments A thread-safe function called from another thread reaches JS through a uv_async_t on its environment's loop and an AsyncResource::CallbackScope, so in a same-process child window it used to run under the opener's context and abort in InternalCallbackScope. Give the echo fixture a thread-safe variant and exercise it alongside the async work. Refs #33868 * refactor: set the isolate up for Node.js once per isolate Pull the IsolateSettings / SetIsolateUpForNode / host-import-callback block out of NodeBindings::CreateEnvironment into NodeBindings::SetUpIsolate, and call it once from each owner: the renderer client's one-time init, the WebWorkerObserver for its thread's isolate, and the browser and utility processes right after their single CreateEnvironment (node's snapshot path resets the isolate error handlers inside CreateEnvironment, so it has to follow it there). Renderer frames no longer re-run isolate setup or stack a message listener per environment. * fix: only lend uv_default_loop() to main frame environments Subframe environments always get a loop of their own; a main frame borrows the process's uv_default_loop() integration while no other environment holds it, so native modules that use the default loop see a consistent main-frame environment. * fix: free a frame's environment under the explicit microtasks policy Restore the explicit microtasks policy around freeing a frame's Node.js environment (its loop runs during teardown, see #33280), and only tear down when the released context is the environment's own. Teardown can now be reached from inside script (an iframe removed with element.remove()), so ExplicitMicrotasksScope no longer asserts a zero microtasks scope depth in the renderer; explicit checkpoints are no-ops there until the enclosing scope unwinds. (cherry picked from commit ec147de)
5 tasks done
MarshallOfSound
approved these changes
Aug 22, 2026
|
Release Notes Persisted
|
3 tasks done
3 tasks done
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #52964
See that PR for details. Trop could not cherry-pick it cleanly; this branch predates
kNoBrowserGlobals, so the save-Blink-fetch blocks stay and there is noWasmResponseExtensionsre-install to move, plus the same utility-process context conflict as 43/44.Notes: Fixed
Uncaught illegal accesserrors and possible renderer crashes after closing a same-process child window or removing an iframe withnodeIntegrationInSubFramesenabled.