Skip to content

Commit 7b38154

Browse files
committed
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: nodejs#24403 Refs: nodejs#25007
1 parent 1395256 commit 7b38154

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/env.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -857,10 +857,13 @@ void Environment::AsyncHooks::grow_async_ids_stack() {
857857
uv_key_t Environment::thread_local_env = {};
858858

859859
void Environment::Exit(int exit_code) {
860-
if (is_main_thread())
860+
if (is_main_thread()) {
861+
stop_sub_worker_contexts();
862+
DisposePlatform();
861863
exit(exit_code);
862-
else
864+
} else {
863865
worker_context_->Exit(exit_code);
866+
}
864867
}
865868

866869
void Environment::stop_sub_worker_contexts() {

src/node.cc

+4
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ tracing::AgentWriterHandle* GetTracingAgentWriter() {
340340
return v8_platform.GetTracingAgentWriter();
341341
}
342342

343+
void DisposePlatform() {
344+
v8_platform.Dispose();
345+
}
346+
343347
#ifdef __POSIX__
344348
static const unsigned kMaxSignal = 32;
345349
#endif

src/node_internals.h

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ int ThreadPoolWork::CancelWork() {
357357
}
358358

359359
tracing::AgentWriterHandle* GetTracingAgentWriter();
360+
void DisposePlatform();
360361

361362
static inline const char* errno_string(int errorno) {
362363
#define ERRNO_CASE(e) case e: return #e;

0 commit comments

Comments
 (0)