src: fix Stop() terminating the next Environment on the isolate - #65819
Open
codebytere wants to merge 1 commit into
Open
src: fix Stop() terminating the next Environment on the isolate#65819codebytere wants to merge 1 commit into
codebytere wants to merge 1 commit into
Conversation
Collaborator
After `Stop(env)`, freeing the Environment and creating another one on the same isolate failed whenever no JavaScript ran in between: the new Environment's first script was terminated before it started. That is the normal case when `Stop()` is called from the process exit handler for an uncaught exception, or by an embedder while the loop is idle. `Stop()` calls `isolate->TerminateExecution()` unless `kDoNotTerminateIsolate` is set, and V8 only clears that request the next time JavaScript runs, so it outlived the Environment it was meant for. Cancel a pending termination when the Environment it was meant for is freed. `Worker::Run()` already did this by hand before freeing its Environment, with a TODO asking why V8 hit a DCHECK without it; this is why, and that call now happens in `FreeEnvironment()`. Refs: nodejs#33347 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65819 +/- ##
==========================================
- Coverage 90.19% 90.18% -0.01%
==========================================
Files 770 770
Lines 264410 264410
Branches 50243 50238 -5
==========================================
- Hits 238490 238464 -26
- Misses 16924 16963 +39
+ Partials 8996 8983 -13
🚀 New features to boost your workflow:
|
codebytere
force-pushed
the
fix/embedder-stop-termination-leak
branch
from
September 5, 2026 17:56
02b1736 to
ec575f4
Compare
Collaborator
Collaborator
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.
After
Stop(env), freeing that Environment and creating a new one on the same isolate fails with the new Environment's first script terminated (LoadEnvironment()aborts) whenever no JavaScript ran in between, which is the normal case whenStop()is called from the process exit handler for an uncaught exception or on an idle Environment:Stop()requestsTerminateExecution()and V8 only clears that request the next time JavaScript runs, so it outlived the Environment it was aimed at.FreeEnvironment()now cancels a pending termination, which can only have been meant for the Environment being freed;Worker::Run()did this by hand with a TODO asking why it was needed, and that call moves intoFreeEnvironment().Tests:
EnvironmentTest.StopFromExitHandlerDoesNotLeakIntoNextEnvironment(aborted before); the worker termination tests pass.Refs: #33347
Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.