mmdevries / eiows

Other
78 stars 4 forks source link

Unable to use eiows with node 16 worker #11

Closed Sam-Gram closed 1 year ago

Sam-Gram commented 2 years ago

I am getting the following error when I try to use eiows with a node 16 worker:

FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
 1: 0xb0a860 node::Abort() [node]
 2: 0xa1c193 node::FatalError(char const*, char const*) [node]
 3: 0xcf97aa v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: 0xcfad0c v8::HandleScope::HandleScope(v8::Isolate*) [node]
 5: 0x7fee205a166e  [/home/sam/Documents/fusion-socketcluster/node_modules/eiows/dist/eiows_linux_93.node]
 6: 0x156d839  [node]
 7: 0x1565f48 uv_run [node]
 8: 0xa43dd5 node::SpinEventLoop(node::Environment*) [node]
 9: 0xb4ca06 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [node]
10: 0xace5a2 node::Start(int, char**) [node]
11: 0x7fee22e19083 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
12: 0xa4067c  [node]
Aborted (core dumped)

I am on Ubuntu 20.04.4 LTS Node 16.16.0 eiows: 4.1.2 socket.io 4.5.1 g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

If I try to require eiows in the main thread I get:

ompilation of µWebSockets has failed and there is no correct pre-compiled binary available for your system or an unsupported node version is used. Please install a supported C++17 compiler or update node and reinstall the module 'eiows'.
    at /home/sam/Documents/fusion-socketcluster/node_modules/eiows/dist/eiows.js:27:15
    at Object.<anonymous> (/home/sam/Documents/fusion-socketcluster/node_modules/eiows/dist/eiows.js:30:3)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at run (/home/sam/Documents/fusion-socketcluster/worker.js:47:22)
    at Object.<anonymous> (/home/sam/Documents/fusion-socketcluster/worker.js:290:1)
Emitted 'error' event on Worker instance at:
    at Worker.[kOnErrorMessage] (node:internal/worker:289:10)
    at Worker.[kOnMessage] (node:internal/worker:300:37)
    at MessagePort.<anonymous> (node:internal/worker:201:57)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:643:20)
    at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
    at Worker.[kOnExit] (node:internal/worker:267:5)
    at Worker.<computed>.onexit (node:internal/worker:198:20)
Sam-Gram commented 2 years ago

Also just wanted to say thank you for maintaining this, good work.

richardpickett commented 1 year ago

I'm having a similar issue.

I have no problem when I run on my local dev machine.

When I bundle this up in a docker container and deploy it, I get the same "Compilation of µWebSockets has failed and there is no correct pre-compiled binary available..." error as @Sam-Gram.

This is built on a box that has the gcc compiler installed, and npm ci throws no errors at all, so I can only assume it gets built correctly.

After npm ci, the node_modules and all the other production files are copied into the container, just like it has prior to trying to use eiows, and that worked fine prior to using eiows.

Is this because the container's architecture is different than the host that built it?

richardpickett commented 1 year ago

I created a workaround for my situation.

I perform a two-stage docker build.

The first stage loads all the build tools and libraries necessary to build the eiows optimized code:

RUN apk add build-base
RUN apk add gcompat

Then I call node w/ a .js file that imports eiows and calls new on the Server() constructor. This triggers the build. (probably just the import does it)

Then I start the second stage of the build and copy the node_modules over from the the first stage, along with the rest of the project that I need for the runtime environment.

In the second stage I also have to apk add gcompat to include the correct libraries.

That's it - the server now runs in the container when I deploy it.

Side note, it didn't optimize my performance in any noticeable way.

I have a socket test that connects 12 clients and then does end-to-end pings (one client sends a ping, all the other sockets respond with pong, the pinger then spits out the average end-to-end response).

I tie multiple server instances together with redis (standard socket.io w/redis).

My test would consist of sending the ping every 10ms. round-trips cost about 200ms on average. sometimes that went up to 300-400, sometimes it'd drop below 200, but it typically hung out at 200.

The server where two containers were running would get a load average of 20 and stay there for hours.

After using eiows, with the same tests, all the stats are the roughly the same, ~200ms round-trip and load average of 20.

It's probably optimized for some other usage than what I'm testing w/ my socket.io implementation.

gsteinLTU commented 1 year ago

My issue seemed to be fixed by installing python3 as a prereq.

mmdevries commented 1 year ago

This indeed seems like a build environment issue. Closing this issue now. Please reopen when you still experiencing issues.