Skip to content

Commit 5fe7741

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: #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>
1 parent b67c4b4 commit 5fe7741

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
@@ -862,10 +862,13 @@ void Environment::AsyncHooks::grow_async_ids_stack() {
862862
uv_key_t Environment::thread_local_env = {};
863863

864864
void Environment::Exit(int exit_code) {
865-
if (is_main_thread())
865+
if (is_main_thread()) {
866+
stop_sub_worker_contexts();
867+
DisposePlatform();
866868
exit(exit_code);
867-
else
869+
} else {
868870
worker_context_->Exit(exit_code);
871+
}
869872
}
870873

871874
void Environment::stop_sub_worker_contexts() {

src/node.cc

+4
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ tracing::AgentWriterHandle* GetTracingAgentWriter() {
337337
return v8_platform.GetTracingAgentWriter();
338338
}
339339

340+
void DisposePlatform() {
341+
v8_platform.Dispose();
342+
}
343+
340344
#ifdef __POSIX__
341345
static const unsigned kMaxSignal = 32;
342346
#endif

src/node_internals.h

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

360360
tracing::AgentWriterHandle* GetTracingAgentWriter();
361+
void DisposePlatform();
361362

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

0 commit comments

Comments
 (0)