From b3c539add1bfebee54ae45e153586f2c07b062ab Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 4 Dec 2018 12:39:30 +0100 Subject: [PATCH] src: dispose of V8 platform in `process.exit()` Calling `process.exit()` calls the C `exit()` function, which in turn calls the destructors of static C++ objects. This can lead to race conditions with other concurrently executing threads; disposing of the V8 platform instance helps with this (although it might not be a full solution for all problems of this kind). Fixes: https://github.com/nodejs/node/issues/24403 --- src/env.cc | 6 ++++-- src/node.cc | 4 ++++ src/node_internals.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/env.cc b/src/env.cc index bdb3c1ea247e21..ffc8b3fcfef271 100644 --- a/src/env.cc +++ b/src/env.cc @@ -849,10 +849,12 @@ void Environment::AsyncHooks::grow_async_ids_stack() { uv_key_t Environment::thread_local_env = {}; void Environment::Exit(int exit_code) { - if (is_main_thread()) + if (is_main_thread()) { + DisposePlatform(); exit(exit_code); - else + } else { worker_context_->Exit(exit_code); + } } void Environment::stop_sub_worker_contexts() { diff --git a/src/node.cc b/src/node.cc index ad0afd437dd4b5..f368e7773bd611 100644 --- a/src/node.cc +++ b/src/node.cc @@ -338,6 +338,10 @@ tracing::AgentWriterHandle* GetTracingAgentWriter() { return v8_platform.GetTracingAgentWriter(); } +void DisposePlatform() { + v8_platform.Dispose(); +} + #ifdef __POSIX__ static const unsigned kMaxSignal = 32; #endif diff --git a/src/node_internals.h b/src/node_internals.h index 6cb40c9070e6a0..89f44efb5e46ed 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -357,6 +357,7 @@ int ThreadPoolWork::CancelWork() { } tracing::AgentWriterHandle* GetTracingAgentWriter(); +void DisposePlatform(); static inline const char* errno_string(int errorno) { #define ERRNO_CASE(e) case e: return #e;