Skip to content

Commit

Permalink
src: lock the isolate properly in IsolateData destructor
Browse files Browse the repository at this point in the history
Otherwise it may fail the DCHECK that uses the locked thread
as a fast path to get the current thread.

PR-URL: #57031
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
joyeecheung authored Feb 15, 2025
1 parent 579fc67 commit d384151
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ IsolateData::IsolateData(Isolate* isolate,

IsolateData::~IsolateData() {
if (cpp_heap_ != nullptr) {
v8::Locker locker(isolate_);
// The CppHeap must be detached before being terminated.
isolate_->DetachCppHeap();
cpp_heap_->Terminate();
Expand Down
3 changes: 3 additions & 0 deletions test/cctest/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ TEST_F(EnvironmentTest, InspectorMultipleEmbeddedEnvironments) {
// This test sets a global variable in the child Environment, and reads it
// back both through the inspector and inside the child Environment, and
// makes sure that those correspond to the value that was originally set.
v8::Locker locker(isolate_);
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env {handle_scope, argv};
Expand Down Expand Up @@ -507,6 +508,7 @@ TEST_F(EnvironmentTest, InspectorMultipleEmbeddedEnvironments) {
CHECK_NOT_NULL(isolate);

{
v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);

Expand Down Expand Up @@ -630,6 +632,7 @@ TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) {

// Try creating Context + IsolateData + Environment.
{
v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);

Expand Down
1 change: 1 addition & 0 deletions test/cctest/test_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ TEST_F(NodeZeroIsolateTestFixture, IsolatePlatformDelegateTest) {

// Try creating Context + IsolateData + Environment
{
v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);

Expand Down

0 comments on commit d384151

Please sign in to comment.