-
Notifications
You must be signed in to change notification settings - Fork 158
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
v8::Platform / node integration discussion #133
Comments
If it helps, I’ve been meaning to look at how this project handles those things to see whether we could use them in
I think it would really help if you could gives some details here – in what way are these thing too Node.js-specific, and how could we make using Node’s
That actually turned out to be kind of a dumb bug in
Thank you for reaching out! I’d be happy to see what we can do to make this module easier to maintain. |
I suspect the approach this project takes wouldn't meet the standards of core nodejs. v8 stops short of making any kind of assurance that you can safely enforce memory or execution limits. The safeguards in place in this project are really just heuristics that attempt to shut down any troublesome isolate before v8 crashes the whole process. It works pretty well but it's far from bulletproof.
I think that's just a bandaid for the issue when using
I think the crux of the issue is that class IsolatePlatformDelegate {
virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner() = 0;
virtual bool IdleTasksEnabled() = 0;
// also several deprecated methods?
} Then the second parameter of |
Okay, that was my experience with former attempts as well. Thanks for confirming that :)
It’s been a few days since then but I was actually kind of sure that I had figured that out with Shelley too – either way, I can confirm that it’s being worked on.
I think that’s mostly true, yes – Electron uses the platform provided by
It’s a bit more complicated than that – I know that Electron does initialize a Node.js platform instance under some circumstances.
Right, that probably makes sense. I’ll try to make sure we figure this out.
Okay, so the tl;dr is, you want to be able to control scheduling for your Isolates on your own, right?
👍
One additional things that
Maybe? I’d have to check with them to see what would help them possibly reconcile the two platform implementations… |
I threw together a straw man proposal for what this might look like: laverdet/node@27d9ef4
The main problem I hiccup I ran into is that |
@laverdet I’ll take a closer look tomorrow, but a few thoughts:
|
Oops, I was trying to get a diff out quickly for discussion I didn't notice I was on an old branch. The newer code is a much better starting point because
The problem I have with that is then you're giving the platform implementation control over the lifecycle of your object.
The new patch is source compatible but not ABI compatible. Adding a new virtual function to a class changes the vtable layout so NODE_MODULE_VERSION would need to be incremented. I think you guys allow that kind of change during odd-numbered releases? |
Yeah, that would seem like a good idea – I’ll leave a comments on the commit the way I would during code review, I hope that’s fine with you. The patch basically looks good to me.
Yeah, I’m personally okay with the first variant, it’s quite a bit cleaner now. :)
Quoting our policy file on this:
I guess maybe we could make an exception here because this is exclusively embedder-focused and there are no known users that use Node.js as a shared/static library? |
@laverdet Are there other things you’d like to see from Node.js to help you here? |
@addaleax thanks, everything looks good on my end. I implemented this in 7087645 and tested it against node master, everything worked out great. I believe that once electron/electron#18540 is taken care of this module will run under Electron once more. And it should run fine using ELECTRON_RUN_AS_NODE once Electron integrates nodejs v14.x. |
Anna [@addaleax],
I have some questions about node_platform and how it relates back to this project.
isolated-vm
is a module which lets users create v8 isolates from scratch which run in the nodejs process but in separate threads. It's similar toworker_threads
which I know you had a significant role in building. Isolated-vm is a bit different in that it specializes in running untrusted or semi-trusted code. To that end it handles some things that worker_threads doesn't care about, like graceful OOM errors and runaway execution prevention.As you know, v8::Platform is a singleton responsible for scheduling tasks per isolate. This means that at some point some master has to be in charge of all the isolates & tasks created in a process, but today we don't really have a good way to plug in to the global platform instance.
MultiIsolatePlatform
,IsolateData
, andPerIsolatePlatformData
do too much and assume too many node-specific things to be useful for isolated-vm.Right now the way I'm accomplishing this is by calling into v8 internals to swap out the platform with a delegate of my own construction. My platform maintains a pointer to the original platform instance and will forward calls for any isolate it doesn't control. It's a very javascripty monkey-patch solution. This has the disadvantage that the library won't load on builds of node that don't export internal symbols.
I also believe Electron is running into issues with the singleton problem too-- electron/electron#18540
I'd like your thoughts on what the best way forward here is. I'm happy to hack some features into nodejs but I want to make sure I'm on the right track first.
Thanks!
The text was updated successfully, but these errors were encountered: