Socket.io: Socket.io server crash on client connect @1.7.3 due to bufferutil and utf-8-validate

Created on 8 Mar 2017  路  9Comments  路  Source: socketio/socket.io

Note: for support questions, please use one of these channels: stackoverflow or slack

You want to:

  • [x] report a bug
  • [ ] request a feature

Current behaviour

Steps to reproduce (if the current behaviour is a bug)

1) Start headless socket.io server with:

require('dotenv').config();
var Server = require('socket.io');

var io = new Server();

io.on('connection', function(client){

  console.log("a new connection was received!");

client.on('request_payload', function (from, msg) {
    console.log('I received a private message by ', from, ' saying ', msg);
  });


  client.on('disconnect', function(){
    console.error("Client disconnected!");
  })

});

console.log(`Started socket server on port ${process.env.SOCKET_SERVER_PORT}`);

io.listen(process.env.SOCKET_SERVER_PORT);

2) Attempt client side connection with socket.[email protected]

         var socket = io(`ws://127.0.0.1:9090/`);
         socket.on('connect', function(){
             console.log('connected!');
         });
  socket.on('event', function(data){});
  socket.on('disconnect', function(){
      console.log('disconnected');
  });

Note that I'm using webpack as my build system, and taking in socket.io-client through an import instead of it being served down in the /socket.io route like it usually should, though I doubt this should matter.

The server runs fine if there are no incoming connections. As soon as a client tries to connect I get the issue seen below.

Expected behaviour

Not crash

Setup

  • OS: Windows and Linux (ubuntu)
  • browser: Chrome
  • socket.io version: 1.7.3

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Node version: 7.5.0

> node socketapp/server.js
Started socket server on port 9090
a new connection was received!
C:\Users\Coop\Documents\Github\lora_demo_server\node_modules\ws\lib\Receiver.js:306
  if (mask != null && buf != null) bufferUtil.unmask(buf, mask);
                                             ^

TypeError: Cannot read property 'unmask' of undefined
    at Receiver.unmask (C:\Users\Coop\Documents\Github\lora_demo_server\node_modules\ws\lib\Receiver.js:306:46)
    at Receiver.finish (C:\Users\Coop\Documents\Github\lora_demo_server\node_modules\ws\lib\Receiver.js:505:25)
    at Receiver.expectHandler (C:\Users\Coop\Documents\Github\lora_demo_server\node_modules\ws\lib\Receiver.js:493:33)
    at Receiver.add (C:\Users\Coop\Documents\Github\lora_demo_server\node_modules\ws\lib\Receiver.js:103:24)
    at Socket.realHandler (C:\Users\Coop\Documents\Github\lora_demo_server\node_modules\ws\lib\WebSocket.js:825:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:189:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)

Most helpful comment

It looks like this is an issue with the ws module. Installing the bufferutil and utf-8-validate modules, as per reccomendation on their npm page breaks the module. The issue seems to be that the api that they use for the mocks doesnt match the api for the most updated versions of these modules. Weird because they list the most updated version of these in their package.json.

Performing an npm remove bufferutil and npm remove utf-8-validate after installation of socket.io seemed to have resolved the issue.

All 9 comments

It looks like this is an issue with the ws module. Installing the bufferutil and utf-8-validate modules, as per reccomendation on their npm page breaks the module. The issue seems to be that the api that they use for the mocks doesnt match the api for the most updated versions of these modules. Weird because they list the most updated version of these in their package.json.

Performing an npm remove bufferutil and npm remove utf-8-validate after installation of socket.io seemed to have resolved the issue.

There is a PR for this in engine.io as it seems: https://github.com/socketio/engine.io/pull/487

Installing the versions [email protected] requires worked for me:

[email protected]
[email protected]

You can use bufferutil@<2 and utf-8-validate@<3 with ws@1.

Removing them completely is something that also worked, though this should probably be documented in the README, as it was an annoying issue to resolve.

At least until ws is upgraded in engine.io

@sergei1152 is there anything else we can do here?

@darrachequesne we released [email protected] with support for all bufferutil and utf-8-validate versions.

@lpinca awesome, as usual. I guess we can close the issue then, thanks.

Was this page helpful?
0 / 5 - 0 ratings