From 281e5a3ceec1a0463d4572a048cff13ea4ade57f Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 27 Jul 2018 18:16:35 +0200 Subject: [PATCH] src: clean up agent loop when exiting through destructor Fixes: https://github.com/nodejs/node/issues/22042 PR-URL: https://github.com/nodejs/node/pull/21867 Reviewed-By: James M Snell Reviewed-By: Eugene Ostroukhov Reviewed-By: Ali Ijaz Sheikh --- src/node.cc | 2 +- src/tracing/agent.cc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 5deeaa6a945df0..886243fd5cdb50 100644 --- a/src/node.cc +++ b/src/node.cc @@ -398,10 +398,10 @@ static struct { } void Dispose() { + tracing_agent_.reset(nullptr); platform_->Shutdown(); delete platform_; platform_ = nullptr; - tracing_agent_.reset(nullptr); } void DrainVMTasks(Isolate* isolate) { diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc index 9b435b56d2c8ad..5a4d637bda0356 100644 --- a/src/tracing/agent.cc +++ b/src/tracing/agent.cc @@ -59,6 +59,7 @@ Agent::Agent() { Agent* agent = ContainerOf(&Agent::initialize_writer_async_, async); agent->InitializeWritersOnThread(); }), 0); + uv_unref(reinterpret_cast(&initialize_writer_async_)); } void Agent::InitializeWritersOnThread() { @@ -72,6 +73,11 @@ void Agent::InitializeWritersOnThread() { } Agent::~Agent() { + categories_.clear(); + writers_.clear(); + + StopTracing(); + uv_close(reinterpret_cast(&initialize_writer_async_), nullptr); uv_run(&tracing_loop_, UV_RUN_ONCE); CheckedUvLoopClose(&tracing_loop_);