Skip to content

src: apply IsolateSettings when using a snapshot - #65407

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:isolate-settings-snapshot
Open

src: apply IsolateSettings when using a snapshot#65407
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:isolate-settings-snapshot

Conversation

@codebytere

@codebytere codebytere commented Aug 19, 2026

Copy link
Copy Markdown
Member

When NewIsolate() is given snapshot data it applies only the misc half of IsolateSettings and leaves the error handlers for later; CreateEnvironment() then installs them with default settings once the main context is deserialized. So with a snapshot, an embedder's fatal_error_callback, oom_error_callback, should_abort_on_uncaught_exception_callback and prepare_stack_trace_callback are dropped, and the message listener is added even if MESSAGE_LISTENER_WITH_ERROR_LEVEL was cleared. The only workaround is calling SetIsolateUpForNode() again after CreateEnvironment().

This makes NewIsolate() apply all of the settings whether or not there is snapshot data, as its comment in node.h already says, and CreateEnvironment() stops touching isolate handlers. The deferral came in with #27321, but every handler copes with there being no Environment yet (without a snapshot they have always been installed before any context exists), and workers already call SetIsolateUpForNode() straight after a snapshot NewIsolate(), so that call goes too.

Tests: embedtest gets an --embedder-isolate-settings mode that goes through NewIsolate()/CreateIsolateData()/CreateEnvironment() with a custom prepare_stack_trace_callback, since CommonEnvironmentSetup takes no settings; the new test-embedding-snapshot-isolate-settings.js checks that callback still formats new Error().stack once the Environment is created from a snapshot; it fails on main and passes here. Embedding suite, cctest and the default suite pass.

Refs: #27321
Refs: #45888


Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.

`NewIsolate()` deferred `SetIsolateErrorHandlers()` when snapshot data
was passed, and `CreateEnvironment()` later installed the handlers with
default `IsolateSettings` after deserializing the main context. An
embedder's `fatal_error_callback`, `oom_error_callback`,
`should_abort_on_uncaught_exception_callback` and
`prepare_stack_trace_callback` were therefore dropped whenever a
snapshot was used, and the per-isolate message listener was added even
if `MESSAGE_LISTENER_WITH_ERROR_LEVEL` had been cleared. The only way
to keep custom handlers was to call `SetIsolateUpForNode()` again after
`CreateEnvironment()`.

Install all handlers in `NewIsolate()` regardless of snapshot data, as
its documentation already describes, and stop touching isolate
handlers in `CreateEnvironment()`. The deferral dates from the initial
isolate snapshot work; every handler already copes with a missing
`Environment`, since without a snapshot they are installed before any
context exists, and workers have been calling `SetIsolateUpForNode()`
right after a snapshot `NewIsolate()` anyway.

Refs: nodejs#27321
Refs: nodejs#45888
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support. labels Aug 19, 2026
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.12%. Comparing base (03fb384) to head (1e39848).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65407      +/-   ##
==========================================
+ Coverage   90.10%   90.12%   +0.01%     
==========================================
  Files         752      752              
  Lines      252209   252201       -8     
  Branches    47454    47446       -8     
==========================================
+ Hits       227260   227289      +29     
+ Misses      16264    16215      -49     
- Partials     8685     8697      +12     
Files with missing lines Coverage Δ
src/api/environment.cc 78.09% <100.00%> (-0.18%) ⬇️
src/node_internals.h 80.35% <ø> (ø)
src/node_worker.cc 81.69% <ø> (-0.13%) ⬇️

... and 35 files with indirect coverage changes

🚀 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.

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants