From b8b92cacd71e615ac1aac19818a19bc3a370c22b Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 31 Jan 2023 15:37:36 +0100 Subject: [PATCH] src: stop tracing agent before shutting down libuv Otherwise there might be pending tracing fs writes which lead to a crash because the libuv threadpool is already gone. Fixes: https://github.com/nodejs/node/issues/46376 PR-URL: https://github.com/nodejs/node/pull/46380 Reviewed-By: theanarkh Reviewed-By: Colin Ihrig Reviewed-By: Yagiz Nizipli Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- src/api/environment.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/environment.cc b/src/api/environment.cc index 406455c7263573..f2adad56ae5284 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -798,6 +798,10 @@ void DefaultProcessExitHandlerInternal(Environment* env, ExitCode exit_code) { env->set_can_call_into_js(false); env->stop_sub_worker_contexts(); env->isolate()->DumpAndResetStats(); + // The tracing agent could be in the process of writing data using the + // threadpool. Stop it before shutting down libuv. The rest of the tracing + // agent disposal will be performed in DisposePlatform(). + per_process::v8_platform.StopTracingAgent(); // 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.