discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

After adding "Zucc" from new PeerDependencies the bot fails to connect #3296

Closed favna closed 5 years ago

favna commented 5 years ago

Please describe the problem you are having in as much detail as possible:

I pulled in latest master and noticed the new peer dependency "zucc". Checked what it was meant to be and thus tried switching from zlib-sync to zucc. However when I tried running my bot subsequently it fails to connect entirely. This is my startup log:

// Registering all my Commando groups, types and commands
// Snip the line where it shows my token
[2019-05-24 21:03:11+02:00] Provider set to SyncSQLiteProvider - will initialise once ready.
Preparing to connect to the gateway...
[WS => Manager] Fetched Gateway Information
      URL: wss://gateway.discord.gg
      Recommended Shards: 1
[WS => Manager] Session Limit Information
      Total: 1000
      Remaining: 999
[WS => Manager] Spawning shards: 0
[WS => Shard 0] Trying to connect to wss://gateway.discord.gg/, version 6
[WS => Shard 0] Setting a HELLO timeout for 20s.
[WS => Shard 0] Opened a connection to the gateway successfully.
>>>>>>
Shard encountered a connection error!
**Shard Number:** 0
**Time:** May 24th 2019 at 21:03:11 UTC+02:00
**Error Message:** Zero length buffer.
<<<<<<
[WS => Shard 0] Did not receive HELLO in time. Destroying and connecting again.
[WS => Shard 0] Clearing the HELLO timeout.
[WS => Shard 0] WebSocket was closed.
      Event Code: 4009
      Clean: undefined
      Reason: No reason received
>>>>>>
Shard is reconnecting!
**Shard Number:** 0
**Time:** May 24th 2019 at 21:03:31 UTC+02:00
<<<<<<
[WS => Shard 0] Shard was destroyed but no WebSocket connection existed... Reconnecting...
>>>>>>
Shard is reconnecting!
**Shard Number:** 0
**Time:** May 24th 2019 at 21:03:31 UTC+02:00
<<<<<<
[WS => Shard 0] Failed to connect to the gateway, requeueing...
[WS => Manager] Shard Queue Size: 1; continuing in 5 seconds...
[WS => Manager] Session Limit Information
        Total: 1000
        Remaining: 999
[WS => Shard 0] Trying to connect to wss://gateway.discord.gg/, version 6
[WS => Shard 0] Setting a HELLO timeout for 20s.
[WS => Shard 0] Opened a connection to the gateway successfully.
>>>>>>
Shard encountered a connection error!
**Shard Number:** 0
**Time:** May 24th 2019 at 21:03:36 UTC+02:00
**Error Message:** Zero length buffer.
<<<<<<

These error logs are from client.shardError and client.shardReconnecting

Further details:

cfanoulis commented 5 years ago

Quick question, have you installed zlib-sync? If so, you need to either pick to use zucc orzlib-sync, as they don't function well together. I also had the same issue, and removing zucc (and keeping zlib-sync) did the trick.

I guess the docs should be updated to reflect that change

favna commented 5 years ago

The code doesn't load zlib-sync if it finds it is capable of loading zucc (by means of a try-catch block) so that should not matter.

That said, yes I did have zlib-sync removed in one attempt as well as present in another.

devsnek commented 5 years ago

zstd doesn't consider being given a zero-length buffer an error, so something else is at play here. can you try to grep for "Zero length buffer" in your node_modules?

favna commented 5 years ago

@devsnek Tried running it but despite having it running in the background it never gave any output (for like 1+ hour). I don't necessarily mind having it run for hours upon hours but....

Ran it like so, just to verify I did not misunderstand you.

image

(please disregard that it shows that I'm using a fork of the lib, it is up2date to the commit hash I mentioned in the original post)

devsnek commented 5 years ago

@Favna you need to pass files to grep or else it waits indefinitely for input on stdin. grep -rni "Zero length buffer" node_modules should work

favna commented 5 years ago

That produces results, in Discordapp's Erlpack.. which in its turn is another peer dependency so that's great ._."

$ grep -rni "Zero length buffer" node_modules 
Binary file node_modules/erlpack/build/Release/erlpack.node matches 
Binary file node_modules/erlpack/build/Release/obj.target/erlpack/js/erlpack.o matches 
Binary file node_modules/erlpack/build/Release/obj.target/erlpack.node matches
node_modules/erlpack/js/erlpack.cc:32:        Nan::ThrowError("Zero length buffer.");
amishshah commented 5 years ago

@Favna can you see if the issue still occurs in https://github.com/discordjs/discord.js/commit/065908956bae6c937de367cddf6ba3a5a092facb?

Crow08 commented 5 years ago

I had the same issue, and now the bot is able to log in again. Most things work again, sadly a new problem has shown up and now I'm getting an error when calling voiceChannel.join():

Error: Zero length buffer.
    at Object.exports.unpack.data [as unpack] ([..]\node_modules\discord.js\src\WebSocket.js:37:18)
    at VoiceWebSocket.onMessage ([..]\node_modules\discord.js\src\client\voice\networking\VoiceWebSocket.js:139:38)
    at WebSocketClient.internalOnMessage ([..]\node_modules\@discordjs\uws\uws.js:103:5)
    at native.client.group.onMessage ([..]\node_modules\@discordjs\uws\uws.js:57:12)

(without erlpack everything works just fine.) I dug a little deeper and noticed that in WebSocket.js line 36 sometimes when data is a string like for example: {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}} new Uint8Array(data) returns an empty Uint8Array: Uint8Array [].

complete debug log:

[VOICE (443496630042492969:2)]: Sending voice state update (queue length is 0): {"guild_id":"443496630042492969","channel_id":"443496630042492973","self_mute":false,"self_deaf":false}
[VOICE] received voice state update: {"channel_id":"443496630042492973","deaf":false,"guild_id":"443496630042492969","mute":false,"self_deaf":false,"self_mute":false,"self_video":false,"session_id":"e237f158a9eb77477e75b00419177eb6","suppress":false,"user_id":"582886421371682827","member":{"deaf":false,"joined_at":"2019-05-28T11:05:26.013798+00:00","mute":false,"nick":null,"premium_since":null,"roles":["582887149494468619"],"user":{"avatar":null,"bot":true,"discriminator":"1492","id":"582886421371682827","username":"UberBot-dev"}}}
[VOICE] connection? true, 443496630042492969 e237f158a9eb77477e75b00419177eb6 443496630042492973
[VOICE (443496630042492969:2)]: Setting sessionID e237f158a9eb77477e75b00419177eb6 (stored as "undefined")
[VOICE (443496630042492969:2)]: Authenticated with sessionID e237f158a9eb77477e75b00419177eb6
[VOICE] received voice server: {"d":{"endpoint":"eu-west410.discord.gg:80","guild_id":"443496630042492969","token":"17148a83df24fcae"},"op":0,"s":13,"t":"VOICE_SERVER_UPDATE"}
[VOICE] voiceServer guild: 443496630042492969 token: 17148a83df24fcae endpoint: eu-west410.discord.gg:80
[VOICE (443496630042492969:2)]: Token "17148a83df24fcae" and endpoint "eu-west410.discord.gg:80"
[VOICE (443496630042492969:2)]: Endpoint resolved as eu-west410.discord.gg
[VOICE (443496630042492969:2)]: Authenticated with sessionID e237f158a9eb77477e75b00419177eb6
[VOICE (443496630042492969:1)]: Connect triggered
[VOICE (443496630042492969:1)]: [WS] connect requested
[VOICE (443496630042492969:1)]: [WS] connecting, 1 attempts, undefined
[VOICE (443496630042492969:1)]: [WS] opened at gateway eu-west410.discord.gg
[VOICE (443496630042492969:1)]: [WS] >> {"op":0,"d":{"server_id":"443496630042492969","user_id":"582886421371682827","token":"17148a83df24fcae","session_id":"e237f158a9eb77477e75b00419177eb6"}}
[VOICE (443496630042492969:1)]: [WS] Error: Error: Zero length buffer.
Error: Zero length buffer.
    at Object.exports.unpack.data [as unpack] ([...]\node_modules\discord.js\src\WebSocket.js:41:18)
    at VoiceWebSocket.onMessage ([...]\node_modules\discord.js\src\client\voice\networking\VoiceWebSocket.js:139:38)
    at WebSocketClient.internalOnMessage ([...]\node_modules\@discordjs\uws\uws.js:103:5)
    at native.client.group.onMessage ([...]\node_modules\@discordjs\uws\uws.js:57:12)
[VOICE (443496630042492969:1)]: [WS] Error: Error: Zero length buffer.
amishshah commented 5 years ago

@Crow08 this should be fixed in https://github.com/discordjs/discord.js/commit/8652e47c14eccd1c8cab27f0d1acb8d7335349e8, can you verify?

Crow08 commented 5 years ago

@amishshah works! Great, thanks!

favna commented 5 years ago

@amishshah on Windows the code works just fine however on my Linux machine (Ubuntu Server LTS, cat /proc/version is Linux version 4.15.0-45-generic (buildd@lgw01-amd64-031) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019) I get the following error:

>>>>>>
Shard encountered a connection error!
**Shard Number:** 0
**Time:** May 29th 2019 at 21:01:19 UTC+00:00
**Error Message:** Bad version number.
<<<<<<

This is based on commit ID 8652e47c14eccd1c8cab27f0d1acb8d7335349e8

And from what I can only presume it really factors in even the type of Linux machine since despite that I say "Windows", I actually use WSL on my windows machine so it's actually "pseudo-linux" even in a way.