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 <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
  • Loading branch information
theanarkh authored and RafaelGSS committed Nov 10, 2022
1 parent b41b5ba commit 42db849
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 @@ -773,8 +773,13 @@ void DefaultProcessExitHandlerInternal(Environment* env, ExitCode 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 42db849

Please sign in to comment.