Skip to content

Commit 84d01ac

Browse files
committed
src: dispose isolate before unregistering it
1 parent 8d5afe1 commit 84d01ac

File tree

11 files changed

+13
-20
lines changed

11 files changed

+13
-20
lines changed

src/api/embed_helpers.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ CommonEnvironmentSetup::~CommonEnvironmentSetup() {
219219
impl_->platform->AddIsolateFinishedCallback(isolate, [](void* data) {
220220
*static_cast<bool*>(data) = true;
221221
}, &platform_finished);
222-
impl_->platform->UnregisterIsolate(isolate);
223222
if (impl_->snapshot_creator.has_value())
224223
impl_->snapshot_creator.reset();
225224
else
226225
isolate->Dispose();
226+
impl_->platform->UnregisterIsolate(isolate);
227227

228228
// Wait until the platform has cleaned up all relevant resources.
229229
while (!platform_finished)

src/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform {
447447

448448
// This function may only be called once per `Isolate`, and discard any
449449
// pending delayed tasks scheduled for that isolate.
450-
// This needs to be called right before calling `Isolate::Dispose()`.
450+
// This needs to be called right after calling `Isolate::Dispose()`.
451451
virtual void UnregisterIsolate(v8::Isolate* isolate) = 0;
452452

453453
// The platform should call the passed function once all state associated

src/node_main_instance.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ NodeMainInstance::~NodeMainInstance() {
8282
Isolate::DisallowJavascriptExecutionScope disallow_js(
8383
isolate_, Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE);
8484
#endif
85-
// This should only be done on a main instance that owns its isolate.
86-
// IsolateData must be freed before UnregisterIsolate() is called.
87-
isolate_data_.reset();
85+
isolate_->Dispose();
8886
platform_->UnregisterIsolate(isolate_);
87+
isolate_data_.reset();
8988
}
90-
isolate_->Dispose();
9189
}
9290

9391
ExitCode NodeMainInstance::Run() {

src/node_worker.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,8 @@ class WorkerThreadData {
234234
*static_cast<bool*>(data) = true;
235235
}, &platform_finished);
236236

237-
// The order of these calls is important; if the Isolate is first disposed
238-
// and then unregistered, there is a race condition window in which no
239-
// new Isolate at the same address can successfully be registered with
240-
// the platform.
241-
// (Refs: https://github.com/nodejs/node/issues/30846)
242-
w_->platform_->UnregisterIsolate(isolate);
243237
isolate->Dispose();
238+
w_->platform_->UnregisterIsolate(isolate);
244239

245240
// Wait until the platform has cleaned up all relevant resources.
246241
while (!platform_finished) {

src/util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ RAIIIsolateWithoutEntering::RAIIIsolateWithoutEntering(const SnapshotData* data)
730730
}
731731

732732
RAIIIsolateWithoutEntering::~RAIIIsolateWithoutEntering() {
733-
per_process::v8_platform.Platform()->UnregisterIsolate(isolate_);
734733
isolate_->Dispose();
734+
per_process::v8_platform.Platform()->UnregisterIsolate(isolate_);
735735
}
736736

737737
RAIIIsolate::RAIIIsolate(const SnapshotData* data)

test/cctest/node_test_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class NodeTestFixture : public NodeZeroIsolateTestFixture {
123123
void TearDown() override {
124124
platform->DrainTasks(isolate_);
125125
isolate_->Exit();
126-
platform->UnregisterIsolate(isolate_);
127126
isolate_->Dispose();
127+
platform->UnregisterIsolate(isolate_);
128128
isolate_ = nullptr;
129129
NodeZeroIsolateTestFixture::TearDown();
130130
}

test/cctest/test_cppgc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ TEST_F(NodeZeroIsolateTestFixture, ExistingCppHeapTest) {
104104
platform->DrainTasks(isolate);
105105
}
106106

107-
platform->UnregisterIsolate(isolate);
108107
isolate->Dispose();
108+
platform->UnregisterIsolate(isolate);
109109

110110
// Check that all the objects are created and destroyed properly.
111111
EXPECT_EQ(CppGCed::kConstructCount, 100);

test/cctest/test_environment.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ TEST_F(EnvironmentTest, InspectorMultipleEmbeddedEnvironments) {
544544
node::FreeIsolateData(isolate_data);
545545
}
546546

547-
data->platform->UnregisterIsolate(isolate);
548547
isolate->Dispose();
548+
data->platform->UnregisterIsolate(isolate);
549549
uv_run(&loop, UV_RUN_DEFAULT);
550550
CHECK_EQ(uv_loop_close(&loop), 0);
551551

@@ -678,8 +678,8 @@ TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) {
678678
}
679679

680680
// Cleanup.
681-
platform->UnregisterIsolate(isolate);
682681
isolate->Dispose();
682+
platform->UnregisterIsolate(isolate);
683683
}
684684
#endif // _WIN32
685685

test/cctest/test_platform.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ TEST_F(NodeZeroIsolateTestFixture, IsolatePlatformDelegateTest) {
104104

105105
// Graceful shutdown
106106
delegate->Shutdown();
107-
platform->UnregisterIsolate(isolate);
108107
isolate->Dispose();
108+
platform->UnregisterIsolate(isolate);
109109
}
110110

111111
TEST_F(PlatformTest, TracingControllerNullptr) {

test/fuzzers/fuzz_env.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class FuzzerFixtureHelper {
6565
void Teardown() {
6666
platform->DrainTasks(isolate_);
6767
isolate_->Exit();
68-
platform->UnregisterIsolate(isolate_);
6968
isolate_->Dispose();
69+
platform->UnregisterIsolate(isolate_);
7070
isolate_ = nullptr;
7171
}
7272
};

0 commit comments

Comments
 (0)