From 613abf2d8a7504effb3e3082785d3ffdd0aa6421 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Fri, 11 May 2018 18:32:35 -0700 Subject: [PATCH] Terminate the engine immediately if there are isolate launch errors. (#5244) --- content_handler/engine.cc | 23 +++++++++++++++++++---- shell/common/engine.cc | 5 +++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/content_handler/engine.cc b/content_handler/engine.cc index 9cc528b9a..369a006e5 100644 --- a/content_handler/engine.cc +++ b/content_handler/engine.cc @@ -204,12 +204,27 @@ Engine::Engine(Delegate& delegate, auto run_configuration = shell::RunConfiguration::InferFromSettings(settings_); + auto on_run_failure = [weak = weak_factory_.GetWeakPtr(), // + runner = + fsl::MessageLoop::GetCurrent()->task_runner() // + ]() { + // The engine could have been killed by the caller right after the + // constructor was called but before it could run on the UI thread. + if (weak) { + weak->Terminate(); + } + }; + shell_->GetTaskRunners().GetUITaskRunner()->PostTask( - fxl::MakeCopyable([engine = shell_->GetEngine(), // - run_configuration = std::move(run_configuration) // + fxl::MakeCopyable([engine = shell_->GetEngine(), // + run_configuration = std::move(run_configuration), // + on_run_failure // ]() mutable { - if (!engine || !engine->Run(std::move(run_configuration))) { - FXL_LOG(ERROR) << "Could not (re)launch the engine in configuration"; + if (!engine) { + return; + } + if (!engine->Run(std::move(run_configuration))) { + on_run_failure(); } })); } diff --git a/shell/common/engine.cc b/shell/common/engine.cc index fc1714c4f..4958e7445 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -109,6 +109,7 @@ bool Engine::Run(RunConfiguration configuration) { } if (!PrepareAndLaunchIsolate(std::move(configuration))) { + FXL_LOG(ERROR) << "Engine not prepare and launch isolate."; return false; } @@ -143,12 +144,12 @@ bool Engine::PrepareAndLaunchIsolate(RunConfiguration configuration) { auto isolate = runtime_controller_->GetRootIsolate(); if (!isolate_configuration->PrepareIsolate(isolate)) { - FXL_DLOG(ERROR) << "Could not prepare to run the isolate."; + FXL_LOG(ERROR) << "Could not prepare to run the isolate."; return false; } if (!isolate->Run(configuration.GetEntrypoint())) { - FXL_DLOG(ERROR) << "Could not run the isolate."; + FXL_LOG(ERROR) << "Could not run the isolate."; return false; } -- GitLab