From 30d783f91ad7cfbaee0b4b69552524aa1f0438e4 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 b906fe10385b94..86498671b5df02 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -797,6 +797,10 @@ void DefaultProcessExitHandler(Environment* env, int 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.