From 48bcfce09e11901244447617be2eb7789427eab0 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 2 May 2019 20:40:21 +0200 Subject: [PATCH] Work around Windows-only V8 concurrent initialization crash This patch provides a work-around for an apparent V8 bug where initializing multiple isolates concurrently leads to a crash on Windows. At the time of writing the cause of this crash is not exactly understood, but it seems to be related to the V8 internal function win64_unwindinfo::RegisterNonABICompliantCodeRange(), which didn't exist in older versions of V8. --- core/libdeno/api.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/libdeno/api.cc b/core/libdeno/api.cc index 1110b1d346094b..81add1d079e202 100644 --- a/core/libdeno/api.cc +++ b/core/libdeno/api.cc @@ -5,6 +5,10 @@ #include #include +// Cpplint bans the use of because it duplicates functionality in +// chromium //base. However Deno doensn't use that, so suppress this lint. +#include // NOLINT + #include "third_party/v8/include/libplatform/libplatform.h" #include "third_party/v8/include/v8.h" #include "third_party/v8/src/base/logging.h" @@ -53,7 +57,20 @@ Deno* deno_new(deno_config config) { params.snapshot_blob = &d->snapshot_; } - v8::Isolate* isolate = v8::Isolate::New(params); + v8::Isolate* isolate; + { +#ifdef _WIN32 + // Work around an apparent V8 bug where initializing multiple isolates + // concurrently leads to a crash. At the time of writing the cause of this + // crash is not exactly understood, but it seems to be related to the V8 + // internal function win64_unwindinfo::RegisterNonABICompliantCodeRange(), + // which didn't exist in older versions of V8. + static std::mutex mutex; + std::lock_guard lock(mutex); +#endif + isolate = v8::Isolate::New(params); + } + d->AddIsolate(isolate); v8::Locker locker(isolate);