Skip to content

Commit dbb45e7

Browse files
addaleaxblattersturm
authored andcommitted
src: cleanup per-isolate state on platform on isolate unregister
Clean up once all references to an `Isolate*` are gone from the `NodePlatform`, rather than waiting for the `PerIsolatePlatformData` struct to be deleted since there may be cyclic references between that struct and the individual tasks. PR-URL: nodejs#20876 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent af5c5b1 commit dbb45e7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/node_platform.cc

+11
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
8686
}
8787

8888
void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
89+
CHECK_NE(flush_tasks_, nullptr);
8990
foreground_tasks_.Push(std::move(task));
9091
uv_async_send(flush_tasks_);
9192
}
9293

9394
void PerIsolatePlatformData::PostDelayedTask(
9495
std::unique_ptr<Task> task, double delay_in_seconds) {
96+
CHECK_NE(flush_tasks_, nullptr);
9597
std::unique_ptr<DelayedTask> delayed(new DelayedTask());
9698
delayed->task = std::move(task);
9799
delayed->platform_data = shared_from_this();
@@ -101,13 +103,21 @@ void PerIsolatePlatformData::PostDelayedTask(
101103
}
102104

103105
PerIsolatePlatformData::~PerIsolatePlatformData() {
106+
Shutdown();
107+
}
108+
109+
void PerIsolatePlatformData::Shutdown() {
110+
if (flush_tasks_ == nullptr)
111+
return;
112+
104113
while (FlushForegroundTasksInternal()) {}
105114
CancelPendingDelayedTasks();
106115

107116
uv_close(reinterpret_cast<uv_handle_t*>(flush_tasks_),
108117
[](uv_handle_t* handle) {
109118
delete reinterpret_cast<uv_async_t*>(handle);
110119
});
120+
flush_tasks_ = nullptr;
111121
}
112122

113123
void PerIsolatePlatformData::ref() {
@@ -148,6 +158,7 @@ void NodePlatform::UnregisterIsolate(IsolateData* isolate_data) {
148158
std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate];
149159
CHECK(existing);
150160
if (existing->unref() == 0) {
161+
existing->Shutdown();
151162
per_isolate_.erase(isolate);
152163
}
153164
}

0 commit comments

Comments
 (0)