-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
When Node addon creates a new isolate, use it to execute JS code and let it triggers GC, it will crash #16658
Comments
Hey! Sounds like you might be interested in something like ayojs/ayo@2f47b5b, which I did for a multi-threading |
Neither really. What you are doing is simply not supported at the current time. Please keep in mind that native modules can do virtually anything (as any other C or C++ code) with no guarantee that you won't explode Node. Until recent times there was never a need to support multiple isolates, so that work was never done or completed. |
@Fishrock123 I understand that multiple isolates are not explicitly supported by Node. However, this issue only happens on Node 8.5.0 or later. When using Node 6.x, 7.x or 8.0~8.4.0, it works as expected without crash. Maybe it is a regression in 8.5.0 release? |
@fs-eire Can you run |
commit found: 9e08695 @addaleax @matthewloring This change introduces a new implementation of v8::Platform. It looks related to this issue. |
@fs-eire Oh, I’m sorry, I didn’t know you were looking for the cause of this. Yes, this happens because Node has its own I’ve opened #16700 with the patch(es) I mentioned above, please feel free to check that out and see whether it helps resolve the issues you were seeing. |
@addaleax I've tested the change. I encountered the following error when calling
|
We have a similar issue during development of a module which uses multiple isolates. |
I've used the example provided above (by @fs-eire ) and I got the following: Using a debug compilation of the node master branch that includes your fixes (on windows) Using a debug compilation of node v9.1 -(on windows) |
Right, there is no way to associate an I’ll think about how to best work around that… it would probably be easiest to expose the default |
Hi @addaleax,
I don't fully understand why multiple
Is there a prototype commit that to prove this idea? If so I would like to have a try on my test. Thanks! |
I'm facing the same issue and I see that #16700 is closed. Does it mean that one of the future versions of Node will support separate unrelated v8 isolates loaded within Node modules? If so, what's the planned timeline for this to be released? Thanks! |
Oh, I see that it's in 9.3.0. Will give it a try. Thanks. |
Just for my understanding - assuming Node is running on thread |
We are talking about the 2nd case. The class |
Until Node exposes the v8 platform in some way or allows users to register their isolates with the v8 platform, it seems not safe to hook into Node's copy of the v8 and maintain separate isolates in the application. I ended up building the v8 as a static library and using it independently from Node. Here's the discussion in the v8 forums, if anyone is interested: https://groups.google.com/d/msg/v8-users/wZHFUrGS2ms/OxosgTf4BQAJ |
@gh-andre We do have |
@addaleax Thanks for pointing out the new method. It will certainly help once it makes it into an LTS release. |
thanks @fs-eire for the clarification and @gh-andre for more context. So the main motivation behind using a native add-on is to get hold of the Node's existing Platform, so as to pin the new isolate into the existing and fully booted And the main motivation behind having a separate isolate is to run some logically related (but structurally separated) JS workload in that, to improve concurrency and throughput? And Hope you don't mind these questions - for me this is an interesting use case.
I don't know whether @fs-eire and @gh-andre work on the same project or not, but for testing purpose if you can use the API ( |
@gireeshpunathil Thanks for chiming in.
I have a large native app running on Node and a lot of legacy JavaScript code implemented using MS COM JavaScript that runs a ton of JS in parallel within the same process. The desire was to leverage the knowledge of v8 from the Node-based part of the project and reduce the application footprint by not having to host two JS engines. A separate v8 also poses various challenges, like managing which ICU copy is being plugged in, etc.
I wish this would came up a couple of months ago. I went through a process of testing Node/v8, Chakra and running a separate v8 instance while looking for a solution and ended up using a statically-linked v8, which is completely isolated from the v8 in Node. I'm in the middle of this project and cannot switch at this point, but I am very interested in this new development and when this new method makes into the version of Node we are using (usually an LTS release), I will revisit using a standalone v8 within a Node process. |
just wondering whether landing of worker will make things better here? /cc @addaleax |
I think the node worker helps when the requirement can be fit by using worker API (i.e. |
Worker threads, which are similar to how JXCore approached it years ago, require the main script to route all requests and marshal/unmarshal text between isolates. If one wants to run independent scripts in parallel (i.e. no JS data sharing at all), it seems to be impossible in the current Node. I'm loading a separate instance of v8 to do that, which takes up a lot of resources and requires some development work. It would be nice if there was a way in Node to run scripts independently in their own isolates. |
For the context: const w = require('worker_threads')
if (w.isMainThread) {
new w.Worker(__filename)
console.log('main')
}
else {
console.log('worker')
} $ node --experimental-worker --prof w.js
$ ls -lrt isolate* -rw-r--r-- 1 gireesh user 167250 Jun 14 10:57 isolate-0x37d9ac0-v8.log
-rw-r--r-- 1 gireesh user 204231 Jun 14 10:57 isolate-0x3719c70-v8.log evidently they are running in two different isolates. |
@addaleax It's not about create an addon that runs scripts in new Isolates on a different thread. It's about how the addon can manipulate the thread. For my requirement, specificly, I am thinking about building a thread-pool based on current worker. Some requirements are -
I believe that it's debatable for some of the items above for whether those requirement are valid or not. Those are the current pain point. Just trying to understand what is the preferred way to do. |
I think #30324 should have addressed the requests here. Feel free to re-open or open a new issue if there is more, though. |
Crash error on Ubuntu 16.04.2
Crash error on macOS Sierra 10.12.6
Crash without error outputted to console (Windows7)
Please refer to https://github.com/fs-eire/node-modules-playground/tree/test-node-crash for the code.
Other findings:
We released Napa.js as a Node module sharing the same v8 platform, and created isolates & manipulated them the same way as the sample addon.
A workaround we could think of is to link with a separate v8 shared library if sharing the same platform is not desired. Actually we started by doing that, but afterwards changed to dynamic linking to V8 from Node for easier build and distribution.
Please kindly suggest if this is a bug in Node, or a behavior by design.
The text was updated successfully, but these errors were encountered: