Skip to content

Commit 2131b5a

Browse files
committed
src: call uv_library_shutdown before DisposePlatform
When the process exits, there may be tasks in the thread pool that need to access data in the platform, such as trace agent. So make sure the thread pool exits first. see #44458
1 parent 806ea92 commit 2131b5a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/api/environment.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,13 @@ void DefaultProcessExitHandlerInternal(Environment* env, ExitCode exit_code) {
773773
env->set_can_call_into_js(false);
774774
env->stop_sub_worker_contexts();
775775
env->isolate()->DumpAndResetStats();
776-
DisposePlatform();
776+
// When the process exits, the tasks in the thread pool may also need to
777+
// access the data of V8Platform, such as trace agent, or a field
778+
// added in the future. So make sure the thread pool exits first.
779+
// And make sure V8Platform don not call into Libuv threadpool, see Dispose
780+
// in node_v8_platform-inl.h
777781
uv_library_shutdown();
782+
DisposePlatform();
778783
Exit(exit_code);
779784
}
780785

src/node_v8_platform-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ struct V8Platform {
103103
platform_ = new NodePlatform(thread_pool_size, controller);
104104
v8::V8::InitializePlatform(platform_);
105105
}
106-
106+
// Make sure V8Platform don not call into Libuv threadpool,
107+
// see DefaultProcessExitHandlerInternal in environment.cc
107108
inline void Dispose() {
108109
if (!initialized_)
109110
return;

0 commit comments

Comments
 (0)