Skip to content
Permalink
Browse files

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 all
Worker threads and then the V8 platform instance helps with this
(although it might not be a full solution for all problems of
this kind).

Refs: #24403
Refs: #25007

PR-URL: #25061
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information...
addaleax committed Dec 4, 2018
1 parent b67c4b4 commit 5fe774104fc2ffa638d9ddfd0df1bdbc7cc84e47
Showing with 10 additions and 2 deletions.
  1. +5 −2 src/env.cc
  2. +4 −0 src/node.cc
  3. +1 −0 src/node_internals.h
@@ -862,10 +862,13 @@ 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()) {
stop_sub_worker_contexts();
DisposePlatform();
exit(exit_code);
else
} else {
worker_context_->Exit(exit_code);
}
}

void Environment::stop_sub_worker_contexts() {
@@ -337,6 +337,10 @@ tracing::AgentWriterHandle* GetTracingAgentWriter() {
return v8_platform.GetTracingAgentWriter();
}

void DisposePlatform() {
v8_platform.Dispose();
}

#ifdef __POSIX__
static const unsigned kMaxSignal = 32;
#endif
@@ -358,6 +358,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;

0 comments on commit 5fe7741

Please sign in to comment.
You can’t perform that action at this time.