uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
8.09k stars 578 forks source link

Worker threads support #232

Closed comods closed 4 years ago

comods commented 4 years ago

NodeJS has a command line switch "--force-context-aware" which prevents some hard to track down errors errors with Electron (electronjs.org) and native modules.

µWS is currently not a context-aware native module.

Here is the documentation about context-aware native modules: https://nodejs.org/api/addons.html#addons_context_aware_addons

I do not know if this is easy or hard to do, or if it will have any effect on performance.

Thanks for this great WebSocket module.

ghost commented 4 years ago

Do you have any example of something that fails? This project is not an Electron module, so any issues with Electron is out of scope.

comods commented 4 years ago

Just using the NodeJS CLI switch "--force-context-aware":

Error: This version of µWS is not compatible with your Node.js build: Error: Loading non context-aware native modules has been disabled

This isn't an error with µWS but a feature request to change the C++ Addon glue code to play nice when multi-threaded.

https://nodejs.org/api/addons.html#addons_context_aware_addons explains it better then I can.

ghost commented 4 years ago

That flag was added like one month ago. And they mention Electron users specifically.

Context aware add-ons sounds sane, but will require dropping nodejs 10 and 11 support from what I can tell. That's not going to happen any time soon.

ghost commented 4 years ago

What, it was added in Node.js 10 it seems: https://nodejs.org/docs/latest-v10.x/api/addons.html#addons_context_aware_addons

ghost commented 4 years ago

This sounds very sane, and should be relatively simple to fix. This will also clean up confusion regarding Isolate and Context in the addon.

An Isolate holds many Contexts, and all functions should only store/load JS data from correct Context. This is vanilla V8 concepts also, so it is not tied to Node.js or Electron.

ghost commented 4 years ago

I have some code here that works. Needs performance fixes though.

ghost commented 4 years ago

This change actually adds Worker threads support

ghost commented 4 years ago

npm install uNetworking/uWebSockets.js#binaries

You can try it