Repository navigation
fix: crash when destroying node env with pending promises - #33280
Merged
Merged
Conversation
codebytere
reviewed
Mar 15, 2022
codebytere
left a comment
Member
There was a problem hiding this comment.
We should add a test - we should just need a very big file to load via fs.promises.read
deepak1556
force-pushed
the
robo/fix_node_env_crash
branch
from
March 16, 2022 07:22
4d92d7f to
f4fa04a
Compare
codebytere
approved these changes
Mar 16, 2022
|
Release Notes Persisted
|
This was referenced Mar 16, 2022
Contributor
|
I have automatically backported this PR to "15-x-y", please check out #33300 |
Contributor
|
I have automatically backported this PR to "16-x-y", please check out #33301 |
Contributor
|
I have automatically backported this PR to "18-x-y", please check out #33302 |
Contributor
|
I have automatically backported this PR to "17-x-y", please check out #33303 |
Member
Author
|
/trop run backport |
Contributor
|
The backport process for this PR has been manually initiated - here we go! :D |
Contributor
|
I have automatically backported this PR to "17-x-y", please check out #33335 |
bavulapati
pushed a commit
to bavulapati/electron
that referenced
this pull request
Apr 29, 2022
…3280) * fix: crash when destroying node env with pending promises * chore: add spec
khalwa
pushed a commit
to solarwindscloud/electron
that referenced
this pull request
Feb 22, 2023
…3280) * fix: crash when destroying node env with pending promises * chore: add spec
codebytere
added a commit
that referenced
this pull request
Aug 19, 2026
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.
codebytere
added a commit
that referenced
this pull request
Aug 20, 2026
…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.
jkleinsc
pushed a commit
that referenced
this pull request
Aug 20, 2026
…me closes (#53040) fix: illegal access errors when a same-process child window or subframe 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)
MarshallOfSound
pushed a commit
that referenced
this pull request
Aug 22, 2026
…me closes (#53042) * fix: illegal access errors when a same-process child window or subframe 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) * chore: fix lint
codebytere
added a commit
that referenced
this pull request
Aug 24, 2026
…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)
MarshallOfSound
pushed a commit
that referenced
this pull request
Aug 25, 2026
…me closes (#53041) * fix: illegal access errors when a same-process child window or subframe 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) * chore: fix lint
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.
Description of Change
Fixes #33164
Checklist
npm testpassesRelease Notes
Notes: fix crash in the render process on reload with pending node fs.promises