From d3841517e980d8b6c64dd6be3de4472c986d7866 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 16 Feb 2025 00:49:38 +0100 Subject: [PATCH] src: lock the isolate properly in IsolateData destructor Otherwise it may fail the DCHECK that uses the locked thread as a fast path to get the current thread. PR-URL: https://github.com/nodejs/node/pull/57031 Reviewed-By: Chengzhong Wu Reviewed-By: Yagiz Nizipli Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Rafael Gonzaga --- src/env.cc | 1 + test/cctest/test_environment.cc | 3 +++ test/cctest/test_platform.cc | 1 + 3 files changed, 5 insertions(+) diff --git a/src/env.cc b/src/env.cc index cd7203ffda6e7c..7c1511794bd8e3 100644 --- a/src/env.cc +++ b/src/env.cc @@ -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(); diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index 14e82cc80ff730..008cda77b650dc 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -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}; @@ -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); @@ -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); diff --git a/test/cctest/test_platform.cc b/test/cctest/test_platform.cc index fdd51da316ace9..037b6b9cffae85 100644 --- a/test/cctest/test_platform.cc +++ b/test/cctest/test_platform.cc @@ -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);