-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
worker: don't use two-arg NewIsolate #29850
Conversation
fbb66b2
to
e4b8809
Compare
e4b8809
to
b8bcdc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM with @bnoordhuis comments addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is Electron initiating Node.js here? The NewIsolate()
and CreateIsolateData()
variants that take a MultiIsolatePlatform*
argument are kind of supposed to solve this problem, but it seems Electron is doing something else?
If we do land this, I’d like to make it clear from the beginning that this is a temporary hack to support Electron, and maybe deprecate it immediately.
@addaleax when |
@codebytere I’m surprised … that code is missing a deallocation corresponding to Is there an Electron bug report corresponding to this/Can you maybe share more info about the crash you’re referring to in the PR description itself (e.g. a reproduction/stack trace)? Otherwise I’m also happy to try and build Electron myself… :) |
@codebytere Maybe for more context, what I’m thinking is that, at least once the Node.js Environment is set up, all attempts to access the underlying platform should use |
I think the thing i'm not quite sure on at the moment is how this might have worked previously - doesn't The crash is just that - it fails here @ L233 with |
@codebytere Yes, but I’d say that As far as I can tell, it is only used in Node.js when running Node.js through |
In |
@codebytere Thanks! I think that’s a clear oversight (and most likely on my part, sorry). Does this help? diff --git a/src/node_worker.cc b/src/node_worker.cc
index 11e44a92757e..3dce5e25980c 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -116,7 +116,10 @@ class WorkerThreadData {
: w_(w) {
CHECK_EQ(uv_loop_init(&loop_), 0);
- Isolate* isolate = NewIsolate(w->array_buffer_allocator_.get(), &loop_);
+ Isolate* isolate = NewIsolate(
+ w->array_buffer_allocator_.get(),
+ &loop_,
+ w->platform_);
CHECK_NOT_NULL(isolate);
{ |
Ah, awesome! That's a far simpler fix so i'm all for it haha I'll update this PR with that simpler change as soon as i verify :D |
b8bcdc0
to
ea00cac
Compare
@addaleax updated and verified in Electron ⭐️ Thanks for the assist! |
PR-URL: #29850 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Landed in 6db45bf |
PR-URL: #29850 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Electron creates and initializes the V8 platform ourselves, and so need to build with
NODE_USE_V8_PLATFORM
set tofalse
and as a result were unable to useworker_threads
.This PR fixes this problem by swapping the two-arg call to NewIsolate present in
NodeWorkerData
for the three-arg version.Before, the two-arg version calls the three-arg version with
GetMainThreadMultiIsolatePlatform()
, which is implemented withper_process::v8_platform.Platform()
. That returnsnullptr
whenNODE_USE_V8_PLATFORM
set tofalse
, and causes a bad access crash.cc @joyeecheung @addaleax
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes