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

uWebSockets and FreeBSD #7710

Closed
nanaya opened this Issue Jun 2, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@nanaya

nanaya commented Jun 2, 2018

I don't know how much you guys care about FreeBSD compatibility, but switching to uws caused streaming server to stop working because it doesn't support FreeBSD.

/home/edho-mastodon/mastodon/node_modules/uws/uws.js:38
            throw new Error('Compilation of µWebSockets has failed and there is no pre-compiled binary ' +
            ^

Error: Compilation of µWebSockets has failed and there is no pre-compiled binary available for your system. Please install a supported C++11 compiler and reinstall the module 'uws'.

Thankfully it seems to be still mostly compatible with the original ws module so switching back to it and updating one deprecation fixes it (or at least seems to fix it, haven't done extensive test).

I imagine something like OS check to figure out which websocket module to use would allow using best available websocket module for each OSes.

The diff looks like something like this (ignore fs import which I'm using to listen to socket file instead of ip address).

diff --git a/streaming/index.js b/streaming/index.js
index 4eaf66865..60962fd87 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -7,8 +7,9 @@ const redis = require('redis');
 const pg = require('pg');
 const log = require('npmlog');
 const url = require('url');
-const WebSocket = require('uws');
+const WebSocket = require('ws');
 const uuid = require('uuid');
+const fs = require('fs');

 const env = process.env.NODE_ENV || 'development';

@@ -503,8 +504,11 @@ const startWorker = (workerId) => {

   const wss = new WebSocket.Server({ server, verifyClient: wsVerifyClient });

-  wss.on('connection', ws => {
-    const req      = ws.upgradeReq;
+  wss.on('connection', (ws, req) => {
+    // stolen from https://github.com/herenow/wsProxy/pull/5
+    if (ws.upgradeReq === undefined) {
+        ws.upgradeReq = req;
+    }
     const location = url.parse(req.url, true);
     req.requestId  = uuid.v4();
     req.remoteAddress = ws._socket.remoteAddress;
@ignisf

This comment has been minimized.

Contributor

ignisf commented Jun 2, 2018

Hey, are you sure it's due to lack of FreeBSD support and not because the current uws dep version does not support node 10? Could you check the build log?

@nightpool

This comment has been minimized.

Collaborator

nightpool commented Jun 2, 2018

closing as dupe of #6853/#7448 (tracking issue for node 10 support)

@nightpool nightpool closed this Jun 2, 2018

@nanaya

This comment has been minimized.

nanaya commented Jun 2, 2018

Thanks, that looks like it. Though seems like there's different error when building uws 10.x on node 8/10 on freebsd at the moment.

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