From f8faf36c8c352133e7da1ff97c981acf99fb99e7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 12 Jan 2019 21:26:12 +0100 Subject: [PATCH 1/2] src: reset `StopTracingAgent()` before platform teardown This makes sure that `StopTracingAgent()` is always called before tearing down the `tracing::Agent`, since previously its destructor might have tried to access the agent, which would be destroyed by the (earlier) `Dispose()` call. --- src/node.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/node.cc b/src/node.cc index 7a585646f66ec4..e559f2232666ed 100644 --- a/src/node.cc +++ b/src/node.cc @@ -240,6 +240,7 @@ static struct { } void Dispose() { + StopTracingAgent(); platform_->Shutdown(); delete platform_; platform_ = nullptr; @@ -579,7 +580,6 @@ static void WaitForInspectorDisconnect(Environment* env) { void Exit(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); WaitForInspectorDisconnect(env); - v8_platform.StopTracingAgent(); int code = args[0]->Int32Value(env->context()).FromMaybe(0); env->Exit(code); } @@ -1436,7 +1436,6 @@ int Start(int argc, char** argv) { per_process::v8_initialized = true; const int exit_code = Start(uv_default_loop(), args, exec_args); - v8_platform.StopTracingAgent(); per_process::v8_initialized = false; V8::Dispose(); From f1e99633d5f4afd16c3056ebd02e3e9b7e195900 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 12 Jan 2019 21:28:48 +0100 Subject: [PATCH 2/2] src: call `Environment::Exit()` for fatal exceptions Call `Environment::Exit()` rather than the process-wide `exit()` function, since JS exceptions generally only affect the current JS engine instance. --- src/node_errors.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 9ffd8d88f1e473..4a9a08e15021d6 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -322,7 +322,7 @@ TryCatchScope::~TryCatchScope() { if (HasCaught() && !HasTerminated() && mode_ == CatchMode::kFatal) { HandleScope scope(env_->isolate()); ReportException(env_, Exception(), Message()); - exit(7); + env_->Exit(7); } } @@ -381,7 +381,7 @@ void FatalException(Isolate* isolate, // Failed before the process._fatalException function was added! // this is probably pretty bad. Nothing to do but report and exit. ReportException(env, error, message); - exit(6); + env->Exit(6); } else { errors::TryCatchScope fatal_try_catch(env); @@ -397,7 +397,7 @@ void FatalException(Isolate* isolate, if (fatal_try_catch.HasCaught()) { // The fatal exception function threw, so we must exit ReportException(env, fatal_try_catch); - exit(7); + env->Exit(7); } else if (caught.ToLocalChecked()->IsFalse()) { ReportException(env, error, message); @@ -408,9 +408,9 @@ void FatalException(Isolate* isolate, Local code; if (!process_object->Get(env->context(), exit_code).ToLocal(&code) || !code->IsInt32()) { - exit(1); + env->Exit(1); } - exit(code.As()->Value()); + env->Exit(code.As()->Value()); } } }