ws: TypeError: Cannot read property 'unmask' of undefined at Receiver.unmask
I have a very simple node app that uses socket.io. When I connect to the server from an external client it works fine. However, when I attempt to render UI using a browser, the server crashes on TypeError from Receiver.unmask.
My server code:
const express = require('express');
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const PORT = process.env.PORT || 8080;
app.use(express.static('public/dashboard'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/dashboard/index.html');
});
io.on('connection', (client) => {
console.log('Client connected');
client.on('disconnect', () => console.log('Client disconnected'));
});
// broadcast PING to all connected sockets
// hoping to hear back from bots
setInterval(() => io.emit('PING', new Date().toTimeString()), 5000);
http.listen(PORT, function(){
console.log(`listening on *:${PORT}`);
});
UI code:
bunch of HTML and JS
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
</script>
Error on node server side:
socket.io:socket socket connected - writing packet +4ms
socket.io:socket joining room Ipoywx491U9SrqRxAAAA +1ms
socket.io:client writing packet {"type":0,"nsp":"/"} +1ms
socket.io-parser encoding packet {"type":0,"nsp":"/"} +2s
socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +0ms
engine:socket sending packet "message" (0) +10ms
socket.io:socket joined room Ipoywx491U9SrqRxAAAA +4ms
engine upgrading existing transport +16ms
engine:socket might upgrade socket transport from "polling" to "websocket" +1ms
[my_workspace]/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 ([my_workspace]/node_modules/ws/lib/Receiver.js:306:46)
at Receiver.finish ([my_workspace]/node_modules/ws/lib/Receiver.js:505:25)
at Receiver.expectHandler ([my_workspace]/node_modules/ws/lib/Receiver.js:493:33)
at Receiver.add ([my_workspace]/node_modules/ws/lib/Receiver.js:103:24)
at Socket.realHandler ([my_workspace]/node_modules/ws/lib/WebSocket.js:825:20)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
Error in UI:
engine.io-client:socket probe transport "websocket" opened +132ms
universalModuleDefinition:1 engine.io-client:polling polling got data ArrayBuffer +3ms
universalModuleDefinition:1 engine.io-client:socket socket receive: type "message", data "0" +1ms
universalModuleDefinition:1 socket.io-parser decoded 0 as {"type":0,"nsp":"/"} +0ms
universalModuleDefinition:1 engine.io-client:polling polling +5ms
universalModuleDefinition:1 engine.io-client:polling-xhr xhr poll +0ms
universalModuleDefinition:1 engine.io-client:polling-xhr xhr open GET: http://localhost:8080/socket.io/?EIO=3&transport=polling&t=LfNIZqL&sid=LZfZtocuqb1C9V0fAAAA +1ms
universalModuleDefinition:1 engine.io-client:polling-xhr xhr data null +1ms
universalModuleDefinition:1 engine.io-client:socket probe transport "websocket" failed because of error: transport closed +20ms
VM445:2 GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=LfNIZqL&sid=LZfZtocuqb1C9V0fAAAA net::ERR_CONNECTION_REFUSED
(anonymous) @ VM445:2
i.create @ universalModuleDefinition:2
i @ universalModuleDefinition:2
o.request @ universalModuleDefinition:2
o.doPoll @ universalModuleDefinition:2
n.poll @ universalModuleDefinition:2
n.onData @ universalModuleDefinition:2
(anonymous) @ universalModuleDefinition:2
n.emit @ universalModuleDefinition:2
i.onData @ universalModuleDefinition:2
i.onLoad @ universalModuleDefinition:2
hasXDR.r.onreadystatechange @ universalModuleDefinition:2
universalModuleDefinition:1 engine.io-client:socket socket error {"type":"TransportError","description":0} +13ms
universalModuleDefinition:1 socket.io-client:manager error +5ms Error: xhr poll error
at o.n.onError (universalModuleDefinition:2)
at i.<anonymous> (universalModuleDefinition:2)
at i.n.emit (universalModuleDefinition:2)
at i.onError (universalModuleDefinition:2)
at universalModuleDefinition:2
universalModuleDefinition:1 engine.io-client:socket socket close with reason: "transport error" +8ms
Using Node v6.8.1, socket.io 1.7.3 that uses ws@1.1.2. Is this a known issue or am I missing something obvious?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 17 (7 by maintainers)
Adding
engine.ioto your dependencies doesn’t solve anything as it is a dependency of one or more of your other dependencies (karma).Remove the
optionalDependenciescompletely or use@eordano the problem is that engine.io@1.8.3 has a pinned version of
ws.If they upgrate to version
ws@1.1.4the issue should disappear.Do you have
bufferutilas dependency? If so make sure to usebufferutil@1,bufferutil@2is compatible only withws@>=2.0.2.