Skip to content

Commit 4da7e6e

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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 92e95f1 commit 4da7e6e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/env.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,13 @@ void Environment::AsyncHooks::grow_async_ids_stack() {
859859
uv_key_t Environment::thread_local_env = {};
860860

861861
void Environment::Exit(int exit_code) {
862-
if (is_main_thread())
862+
if (is_main_thread()) {
863+
stop_sub_worker_contexts();
864+
DisposePlatform();
863865
exit(exit_code);
864-
else
866+
} else {
865867
worker_context_->Exit(exit_code);
868+
}
866869
}
867870

868871
void Environment::stop_sub_worker_contexts() {

src/node.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ tracing::AgentWriterHandle* GetTracingAgentWriter() {
345345
return v8_platform.GetTracingAgentWriter();
346346
}
347347

348+
void DisposePlatform() {
349+
v8_platform.Dispose();
350+
}
351+
348352
#ifdef __POSIX__
349353
static const unsigned kMaxSignal = 32;
350354
#endif

src/node_internals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ int ThreadPoolWork::CancelWork() {
345345
}
346346

347347
tracing::AgentWriterHandle* GetTracingAgentWriter();
348+
void DisposePlatform();
348349

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

0 commit comments

Comments
 (0)