From b8c9048a87c30f62b333e57697fa45a4b6c01403 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 27 Feb 2020 22:02:12 -0800 Subject: [PATCH] src: shutdown platform from FreePlatform() There is currently no way to properly do this. Backport-PR-URL: https://github.com/nodejs/node/pull/35241 PR-URL: https://github.com/nodejs/node/pull/30467 Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil --- src/node_platform.cc | 6 ++++++ src/node_platform.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node_platform.cc b/src/node_platform.cc index 35444d45506823..f7eefc93f8fece 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -333,6 +333,10 @@ NodePlatform::NodePlatform(int thread_pool_size, std::make_shared(thread_pool_size); } +NodePlatform::~NodePlatform() { + Shutdown(); +} + void NodePlatform::RegisterIsolate(Isolate* isolate, uv_loop_t* loop) { Mutex::ScopedLock lock(per_isolate_mutex_); std::shared_ptr existing = per_isolate_[isolate]; @@ -362,6 +366,8 @@ void NodePlatform::AddIsolateFinishedCallback(Isolate* isolate, } void NodePlatform::Shutdown() { + if (has_shut_down_) return; + has_shut_down_ = true; worker_thread_task_runner_->Shutdown(); { diff --git a/src/node_platform.h b/src/node_platform.h index 3cf526ae3da124..48ced3eac5b5de 100644 --- a/src/node_platform.h +++ b/src/node_platform.h @@ -138,7 +138,7 @@ class NodePlatform : public MultiIsolatePlatform { public: NodePlatform(int thread_pool_size, v8::TracingController* tracing_controller); - ~NodePlatform() override = default; + ~NodePlatform() override; void DrainTasks(v8::Isolate* isolate) override; void Shutdown(); @@ -181,6 +181,7 @@ class NodePlatform : public MultiIsolatePlatform { v8::TracingController* tracing_controller_; std::shared_ptr worker_thread_task_runner_; + bool has_shut_down_ = false; }; } // namespace node