Skip to content

Commit f4be176

Browse files
addaleaxBethGriggs
authored andcommitted
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 Backport-PR-URL: #26048 PR-URL: #25061 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent b9188d4 commit f4be176

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/env.cc

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

675675
void Environment::Exit(int exit_code) {
676-
if (is_main_thread())
676+
if (is_main_thread()) {
677+
stop_sub_worker_contexts();
678+
DisposePlatform();
677679
exit(exit_code);
678-
else
680+
} else {
679681
worker_context_->Exit(exit_code);
682+
}
680683
}
681684

682685
void Environment::stop_sub_worker_contexts() {

src/node.cc

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ static struct {
383383
#endif // !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR
384384
} v8_platform;
385385

386+
void DisposePlatform() {
387+
v8_platform.Dispose();
388+
}
389+
386390
#ifdef __POSIX__
387391
static const unsigned kMaxSignal = 32;
388392
#endif

src/node_internals.h

+2
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ int ThreadPoolWork::CancelWork() {
538538
return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
539539
}
540540

541+
void DisposePlatform();
542+
541543
static inline const char* errno_string(int errorno) {
542544
#define ERRNO_CASE(e) case e: return #e;
543545
switch (errorno) {

0 commit comments

Comments
 (0)