From 531472bad46ebbf78c9d1ef32442b03f675daf68 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Thu, 26 Oct 2017 14:06:34 +0200 Subject: [PATCH] Create a `TaskScheduler` when initializing run-as-node mode. It fixes crashes when V8 tries to execute background tasks via the TaskScheduler. --- atom/app/node_main.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index ec167af6ac3d..cc8df0e0c8fd 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -12,6 +12,7 @@ #include "atom/common/native_mate_converters/string16_converter.h" #include "base/command_line.h" #include "base/feature_list.h" +#include "base/task_scheduler/task_scheduler.h" #include "base/threading/thread_task_runner_handle.h" #include "gin/array_buffer.h" #include "gin/public/isolate_holder.h" @@ -40,6 +41,10 @@ int NodeMain(int argc, char *argv[]) { gin::V8Initializer::LoadV8Snapshot(); gin::V8Initializer::LoadV8Natives(); + + // V8 requires a task scheduler apparently + base::TaskScheduler::CreateAndStartWithDefaultParams("Electron"); + JavascriptEnvironment gin_env; int exec_argc; @@ -88,6 +93,13 @@ int NodeMain(int argc, char *argv[]) { node::FreeEnvironment(env); } + // According to "src/gin/shell/gin_main.cc": + // + // gin::IsolateHolder waits for tasks running in TaskScheduler in its + // destructor and thus must be destroyed before TaskScheduler starts skipping + // CONTINUE_ON_SHUTDOWN tasks. + base::TaskScheduler::GetInstance()->Shutdown(); + v8::V8::Dispose(); return exit_code;