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

WorkerThreads: Cannot create a handle without a HandleScope #1981

Closed
meisterlampe opened this issue Nov 8, 2019 · 8 comments
Closed

WorkerThreads: Cannot create a handle without a HandleScope #1981

meisterlampe opened this issue Nov 8, 2019 · 8 comments

Comments

@meisterlampe
Copy link

Summary of Problem

  • What are you trying to do?
    I want to open a serial connection from within a WorkerThread.
    Maybe I'm using this wrong, any hint how to do it right is much appreciated :-)

  • What happens?
    I get this Error:

FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
 1: 0x9d8da0 node::Abort() [node]
 2: 0x9d9f56 node::OnFatalError(char const*, char const*) [node]
 3: 0xb37b8a v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: 0xb3910e v8::HandleScope::HandleScope(v8::Isolate*) [node]
 5: 0x9498ae node::InternalCallbackScope::InternalCallbackScope(node::Environment*, v8::Local<v8::Object>, node::async_context const&, node::InternalCallbackScope::ResourceExpectation) [node]
 6: 0x94a7c5 node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [node]
 7: 0x7fd0a4c6c042 EIO_AfterOpen(uv_work_s*) [/home/dev/git/test/serialport-vs-workerthread/node_modules/@serialport/bindings/build/Release/bindings.node]
 8: 0x12cfdd5  [node]
 9: 0x12d42d1  [node]
10: 0x12e66a8  [node]
11: 0x12d4c5b uv_run [node]
12: 0xa1afa7 node::NodeMainInstance::Run() [node]
13: 0x9ab298 node::Start(int, char**) [node]
14: 0x7fd0a7a9db97 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
15: 0x949035  [node]
Aborted (core dumped)
  • What should have happened?
    SerialPort should work as normal.

Code to Reproduce the Issue

Minimal reproduction, that leads to the error:

const { Worker } = require('worker_threads');

const worker = new Worker(
    `new require("serialport")("/dev/ttyUSB0");`,
     { eval: true }
);

Running the same new outside the worker works fine:

const { Worker } = require('worker_threads');
new require("serialport")("/dev/ttyUSB0");

Also requiring another library (tried moment here) works as expected:

const { Worker } = require('worker_threads');

const worker = new Worker(
    `console.log((new require("moment"))().toISOString());`,
     { eval: true }
);

Versions, Operating System and Hardware

Could this be related to some child-thread serialport is trying to start?
Please help :-)

@reconbot
Copy link
Member

reconbot commented Nov 9, 2019 via email

@meisterlampe
Copy link
Author

Thank you for your fast answer.
Is support possible/planned?
Any hints what has to be implemented to make it work?

@reconbot
Copy link
Member

reconbot commented Nov 9, 2019 via email

@meisterlampe
Copy link
Author

OK. Thanks for the good answers and of course for this lib too. I guess I can close this question. :)

@reconbot
Copy link
Member

reconbot commented Nov 9, 2019 via email

@meisterlampe
Copy link
Author

Does the addon need to be "context aware" as described in here https://nodejs.org/api/addons.html#addons_context_aware_addons ?

@reconbot
Copy link
Member

It’s the cleanup hooks

https://nodejs.org/api/addons.html#addons_worker_support

@meisterlampe
Copy link
Author

Really looks easier than porting from nan to n-api (at least the description is shorter :-D ).
Maybe I should continue commenting on Issue #1938

@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants