Skip to content

Commit

Permalink
src: call uv_library_shutdown before DisposePlatform
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
theanarkh authored and danielleadams committed Jan 3, 2023
1 parent d7fe2ea commit 8c4ac6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,13 @@ void DefaultProcessExitHandler(Environment* env, int exit_code) {
env->set_can_call_into_js(false);
env->stop_sub_worker_contexts();
env->isolate()->DumpAndResetStats();
DisposePlatform();
// When the process exits, the tasks in the thread pool may also need to
// access the data of V8Platform, such as trace agent, or a field
// added in the future. So make sure the thread pool exits first.
// And make sure V8Platform don not call into Libuv threadpool, see Dispose
// in node_v8_platform-inl.h
uv_library_shutdown();
DisposePlatform();
exit(exit_code);
}

Expand Down
3 changes: 2 additions & 1 deletion src/node_v8_platform-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ struct V8Platform {
platform_ = new NodePlatform(thread_pool_size, controller);
v8::V8::InitializePlatform(platform_);
}

// Make sure V8Platform don not call into Libuv threadpool,
// see DefaultProcessExitHandlerInternal in environment.cc
inline void Dispose() {
if (!initialized_)
return;
Expand Down

0 comments on commit 8c4ac6d

Please sign in to comment.