Skip to content

Commit

Permalink
src: dispose of V8 platform in process.exit()
Browse files Browse the repository at this point in the history
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: nodejs#24403
  • Loading branch information
addaleax committed Dec 4, 2018
1 parent 0c65314 commit b3c539a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/env.cc
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/node.cc
Expand Up @@ -338,6 +338,10 @@ tracing::AgentWriterHandle* GetTracingAgentWriter() {
return v8_platform.GetTracingAgentWriter();
}

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

#ifdef __POSIX__
static const unsigned kMaxSignal = 32;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/node_internals.h
Expand Up @@ -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;
Expand Down

0 comments on commit b3c539a

Please sign in to comment.