AndrewBelt / hack.chat

a minimal, distraction-free chat application
https://hack.chat/
MIT License
2.39k stars 336 forks source link

TypeError: socket._receiver.flush is not a function #136

Open cavebeat opened 7 years ago

cavebeat commented 7 years ago

When i set the nickname and press enter, following error occurs.

chat@chat:~$ cd hack.chat/ chat@chat:/home/chat/hack.chat$ node server.js Loaded config 'config.json' Started server on 0.0.0.0:6060 /home/chat/hack.chat/server.js:64 socket._receiver.flush(); ^

TypeError: socket._receiver.flush is not a function at WebSocket. (/home/chat/hack.chat/server.js:64:21) at emitOne (events.js:115:13) at WebSocket.emit (events.js:210:7) at Receiver._receiver.onmessage (/home/chat/hack.chat/node_modules/ws/lib/WebSocket.js:146:47) at Receiver.dataMessage (/home/chat/hack.chat/node_modules/ws/lib/Receiver.js:389:14) at Receiver.getData (/home/chat/hack.chat/node_modules/ws/lib/Receiver.js:330:12) at Receiver.startLoop (/home/chat/hack.chat/node_modules/ws/lib/Receiver.js:165:16) at Receiver.add (/home/chat/hack.chat/node_modules/ws/lib/Receiver.js:139:10) at Socket._ultron.on (/home/chat/hack.chat/node_modules/ws/lib/WebSocket.js:142:22) at emitOne (events.js:115:13) chat@chat:/home/chat/hack.chat$

root@chat:~# lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 9.1 (stretch) Release: 9.1 Codename: stretch

chat@chat:/home/chat/hack.chat$ node -v v8.4.0

any idea what went wrong? Or what is missing?

raf924 commented 7 years ago

hm yeah I think that code comes from a pull request that was done before the Andrew updated the ws dependency version. try to get the commit before last and see if that works

cavebeat commented 7 years ago

works with https://github.com/AndrewBelt/hack.chat/commit/5ca90f990cacbb7c7ac7c6156929baabb5a3121c

git checkout 5ca90f990cacbb7c7ac7c6156929baabb5a3121c

ping @marzavec

raf924 commented 7 years ago

ok but did you try it with e60ac6936547341c67afdfff327ac40f6da2273b with ws@1.1.1 ?

princenasario commented 6 years ago

I tried it with every commit. I enter the username and it stays blank and when i send a text message, it says Server Disconnected error with the socket flush error in the terminal.

TypeError: socket._receiver.flush is not a function

Loaded config 'config.json' Started server on 0.0.0.0:6060

/home/prince/hack.chat/server.js:64 socket._receiver.flush(); ^

TypeError: socket._receiver.flush is not a function at WebSocket. (/home/prince/hack.chat/server.js:64:21) at emitOne (events.js:96:13) at WebSocket.emit (events.js:191:7) at Receiver._receiver.onmessage (/home/prince/hack.chat/node_modules/ws/lib/WebSocket.js:146:47) at Receiver.dataMessage (/home/prince/hack.chat/node_modules/ws/lib/Receiver.js:389:14) at Receiver.getData (/home/prince/hack.chat/node_modules/ws/lib/Receiver.js:330:12) at Receiver.startLoop (/home/prince/hack.chat/node_modules/ws/lib/Receiver.js:165:16) at Receiver.add (/home/prince/hack.chat/node_modules/ws/lib/Receiver.js:139:10) at Socket._ultron.on (/home/prince/hack.chat/node_modules/ws/lib/WebSocket.js:142:22)

I tried every commit, including the latest commit. It doesn't work. What to do?

The npm error log file says:

0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'start' ] 2 info using npm@5.7.1 3 info using node@v7.10.1 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info lifecycle hack.chat@1.0.0~prestart: hack.chat@1.0.0 6 info lifecycle hack.chat@1.0.0~start: hack.chat@1.0.0 7 verbose lifecycle hack.chat@1.0.0~start: unsafe-perm in lifecycle true 8 verbose lifecycle hack.chat@1.0.0~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/hom$9 verbose lifecycle hack.chat@1.0.0~start: CWD: /home/prince/hack.chat 10 silly lifecycle hack.chat@1.0.0~start: Args: [ '-c', 'node server.js' ] 11 silly lifecycle hack.chat@1.0.0~start: Returned: code: 1 signal: null 12 info lifecycle hack.chat@1.0.0~start: Failed to exec start script 13 verbose stack Error: hack.chat@1.0.0 start: node server.js 13 verbose stack Exit status 1 13 verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16) 13 verbose stack at emitTwo (events.js:106:13) 13 verbose stack at EventEmitter.emit (events.js:194:7) 13 verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:$13 verbose stack at emitTwo (events.js:106:13) 13 verbose stack at ChildProcess.emit (events.js:194:7) 13 verbose stack at maybeClose (internal/child_process.js:899:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) 14 verbose pkgid hack.chat@1.0.0 15 verbose cwd /home/prince/hack.chat

marzavec commented 6 years ago

@princenasario Cd into the directory where you have the server software, run the command:

npm list ws

If the output of npm is different than ws@1.1.1 then you need to remove ws and install version 1.1.1

However, that version of ws is old and slow (not to mention vulnerable to an upgrade header attack). The best recommendation I have is to not use the legacy version and instead use:

https://github.com/hack-chat/main

This is the current software running on https://hack.chat/, it uses version 5.0.0 of the ws library and has been proven stable with over 400 connections.