Skip to content

Commit 8c4ac6d

Browse files
theanarkhdanielleadams
authored andcommitted
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 PR-URL: #45226 Refs: #44458 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent d7fe2ea commit 8c4ac6d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/api/environment.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,13 @@ void DefaultProcessExitHandler(Environment* env, int exit_code) {
779779
env->set_can_call_into_js(false);
780780
env->stop_sub_worker_contexts();
781781
env->isolate()->DumpAndResetStats();
782-
DisposePlatform();
782+
// When the process exits, the tasks in the thread pool may also need to
783+
// access the data of V8Platform, such as trace agent, or a field
784+
// added in the future. So make sure the thread pool exits first.
785+
// And make sure V8Platform don not call into Libuv threadpool, see Dispose
786+
// in node_v8_platform-inl.h
783787
uv_library_shutdown();
788+
DisposePlatform();
784789
exit(exit_code);
785790
}
786791

src/node_v8_platform-inl.h

+2-1
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)