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

Attempting to use roaring from worker_thread throws "Module did not self register" #47

Closed
steveliles opened this issue Mar 3, 2023 · 4 comments

Comments

@steveliles
Copy link

steveliles commented Mar 3, 2023

I'm trying to spin up worker threads (https://nodejs.org/api/worker_threads.html) to take advantage of multiple cpu cores in a project that makes heavy use of roaring, but I get this error:

Error: Module did not self-register: '/Users/Steve/myproject/node_modules/roaring/build/Release/roaring.node'.

Apparently this is to do with native add-ons having to be aware that they might be used from worker threads, and for many modules the fix is relatively simple: nodejs/node#21783 (comment)

Documentation for context-aware addons and some worker_thread specific stuff about cleaning up resources here:
https://github.com/nodejs/node/blob/main/doc/api/addons.md#context-aware-addons

I will try to fork and PR but I have not done any native before, so I'm not massively confident of success ...

@SalvatorePreviti
Copy link
Owner

Thank you for reporting this, yes, I never tried this in a worker thread nor wrote test for it. I am going to write some test code and can work on a fix somewhere in the next 1, 2 weeks

@SalvatorePreviti
Copy link
Owner

Ok yes is a bit more complicated than just setting the module to be context aware, I will need to fix some code that would not work in multiple isolates but is doable

@SalvatorePreviti
Copy link
Owner

Released v1.5.2 that fixes the module initialization to be compatible with worker threads and make the code work with multiple isolates - worker threads are going to work only if node is >= 13 (node 14 is the LTS version)

Please give it a go and let me know.

@steveliles
Copy link
Author

steveliles commented Mar 9, 2023

Early results: seems to be working well for me in multiple worker_threads - thank you so much! 💯

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

Successfully merging a pull request may close this issue.

2 participants