Skip to content

Commit

Permalink
Terminate the engine immediately if there are isolate launch errors. (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored May 12, 2018
1 parent b34ab18 commit 613abf2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 19 additions & 4 deletions content_handler/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}));
}
Expand Down
5 changes: 3 additions & 2 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 613abf2

Please sign in to comment.