Skip to content
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

Having some trouble using rusty_v8 #603

Closed
pepsi opened this issue Sep 24, 2020 · 6 comments
Closed

Having some trouble using rusty_v8 #603

pepsi opened this issue Sep 24, 2020 · 6 comments

Comments

@pepsi
Copy link

pepsi commented Sep 24, 2020

As the title says, using rusty_v8 is not working for me, im on Arch linux x86_64, Node v12.18.1, rustc 1.48.0-nightly (fb1dc34a8 2020-09-21)
I made a simple project with neon new neonb, Filled it out with a basic skeleton for a discord bot, before adding some rust code to initialize the v8 js engine.
it didnt work (Same error as below), so I started stripping away some code, until i was left with just const rusty = require('../native')
and

use neon::prelude::*;
use rusty_v8 as v8;


fn init_v8(mut func_contex: FunctionContext) -> JsResult<JsUndefined>{
    Ok(func_contex.undefined())
}


register_module!(mut cx, {
    cx.export_function("init", init_v8)
});

If i remove the use rusty_v8 as v8; the code compiles just fine, but if I keep it, I get the following error on runtime:

#
# Fatal error in ../../../../v8/src/execution/isolate.h, line 556
# Debug check failed: true == isolate_key_created_.load(std::memory_order_relaxed) (1 vs. 0).
#
#
#
#FailureMessage Object: 0x7fff80618db0./.start.sh: line 2: 531776 Aborted                 (core dumped) node -e 'require("./")'

Im not sure if this is a problem, since rusty_v8 is a binding to Chromium's V8 engine, and neon isnt compatable with things of that nature, but any help on this would be greatly appreciated. I can give more information if needed.
neon-cli version ^0.4.0
neon-build 0.4.0
neon 0.4.0

@kjvalencik
Copy link
Member

Neon is specifically for building modules against node.js and not v8. Neon includes Node header files which in turn include v8 header files. It's likely that these symbol definitions are conflicting.

I am closing this issue because it appears outside the scope of Neon. Please let me know if that's not the case!

@pepsi
Copy link
Author

pepsi commented Sep 24, 2020

I am building against node.js, Im just testing out a "serverless" type thing for discord bots platform, and for that I need to run some js code.
I've found that the easiest way to do that, is with a clean, v8 javscript sandbox.
The plan is to have a nodejs script, that calls into a rust script that spawns a v8 instance.
If you need further clarification about anything along the way, Ill be glad to explain it :)

@kjvalencik
Copy link
Member

kjvalencik commented Sep 24, 2020

I'm not sure if node would support other instances of v8 in the process. There are some globals managed in the threads.

If it is supported, it might be neon-sys that is problematic. Can you try using the napi-runtime backend for Neon? It isn't on feature parity yet, but might help confirm if this direction will work. Add the following to your Cargo.toml:

neon = { version = "0.4.2", default-features = false, features = ["napi-runtime"] } 

An alternative approach is to call into node.js with the EventHandler API and have some glue code in javascript that creates a sandboxed worker to execute the Js.

@pepsi
Copy link
Author

pepsi commented Sep 24, 2020

Thank you, switching to napi-runtime worked perfectly.
Now I can use js to call rust to call js :)
Jokes aside, thank you so much for your help :)

@kjvalencik
Copy link
Member

kjvalencik commented Sep 24, 2020

Glad I could help! That means the issues may have to do with linking. There a few caveats that likely apply:

  • Might not work in Windows since even on n-api that we link to node.lib
  • The napi-runtime does not yet have a way to wrap Rust data in JS objects for management by the garbage collector. This is the JsClass macro in current neon, but will be JsBox. It has not landed yet: Implementation of JsBox #579
  • Similarly, it's not possible to perform asynchronous work (callback to Node from another thread). Currently the Task API. That's currently in the RFC stage: Threadsafe Handles rfcs#32
  • The napi-runtime backend for Neon is not considered production ready. It's an active work in progress.

@pepsi
Copy link
Author

pepsi commented Sep 24, 2020

Who needs windows support anyway?
And the other stuff, I should be able to work around it, so no problems there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants