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

Not working with Worker thread. #97

Open
alexey11231 opened this issue Apr 19, 2021 · 5 comments
Open

Not working with Worker thread. #97

alexey11231 opened this issue Apr 19, 2021 · 5 comments

Comments

@alexey11231
Copy link

If "onMessage" listener is called inside worker thread "Segmentation fault (core dumped) " occurs upon received can msg.

@sebi2k1
Copy link
Owner

sebi2k1 commented Apr 21, 2021

You have a code snippet demonstrating the issue?

@alexey11231
Copy link
Author

main:

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

if (isMainThread) {
 
  new Worker("./worker.js");

}  

worker.js:

 console.log("inThread")

var can = require('socketcan');

var channel = can.createRawChannel("can0", true);
 
channel.addListener("onMessage", function(msg) { console.log(msg); } );
 
channel.addListener("onMessage", channel.send, channel);

channel.start();`

errormsg:

FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
Aborted

Today on first run it gave that msg. Before and after it was throwing segmentation fault.

@juleq
Copy link
Contributor

juleq commented Apr 28, 2021

Seems one would need to litter the cpp code with multithreading protection to support workers.

Could you share why you want to use a worker? The whole node idea is to eleminate multithreading complexity by offering an event driven infrastructure and non-blocking async io. The thread pools node uses for that are hidden under the hood.

@alexey11231
Copy link
Author

Nothing specific. I wanted to put can logic in separate worker, no good reason, just force of habit I guess.
I was just playing around and noticed this, so I decided to inform you about it.

Btw great job with this(node-can), its quite useful. Ty !

@juleq
Copy link
Contributor

juleq commented Apr 29, 2021

These flowers go straight to @sebi2k1 💐.

I have a direct comparison implementing stuff with node in one instance and C# and its TPL in another. I really appreciate the simplicity that the event driven approach provides for IO heavy use cases.

Your feedback regarding workers is definitely a limitation to keep in mind. If someone is interested in making himself familiar with thread safety mechanisms of V8, it could be a nice little project to implement support. But I have used node-can quite extensively in a busy embedded system and I never felt lonely without the thread safety 😃.

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

No branches or pull requests

3 participants