discord.js icon indicating copy to clipboard operation
discord.js copied to clipboard

Zero length buffer error spam for two minutes

Open kevinlul opened this issue 2 years ago • 6 comments

Which package is this bug report for?

discord.js

Issue description

Our client logs reconnect and error events roughly like so:

bot.on("error", message => console.error(`Shard ${bot.shard}: ${message}`));
bot.on("shardReconnecting", shard => console.info(`Shard ${shard} reconnecting`));
2023-02-15T17:30:46.723Z bot:info:events Shard 3 reconnecting

After this event, for the next two seconds from 2023-02-15T17:30:46.901Z to 2023-02-15T17:30:48.381Z, our client logged 91 instances of a Zero length buffer error that we've not seen before. Afterward, bot behaviour appeared typical for the next three hours, until another incident of #8486.

2023-02-15T17:30:46.901Z bot:error:events Shard 3 error: Error: Zero length buffer.
    at exports.unpack (/app/node_modules/discord.js/src/WebSocket.js:27:18)
    at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:313:26)
    at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:199:18)
    at WebSocket.emit (node:events:513:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1178:20)
    at Receiver.emit (node:events:513:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:513:14)
    at Receiver.getData (/app/node_modules/ws/lib/receiver.js:446:17)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:148:22)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:83:10)

All recommended optional dependencies are installed.

	"optionalDependencies": {
		"bufferutil": "^4.0.7",
		"erlpack": "discord/erlpack",
		"utf-8-validate": "^6.0.2",
		"zlib-sync": "^0.1.8"
	}

Code sample

No response

Package version

14.6.0

Node.js version

v18.14.0

Operating system

Docker node:18 base image

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

Channel, Message

Which gateway intents are you subscribing to?

Guilds, GuildMessages, DirectMessages, MessageContent

I have tested this issue on a development release

No response

kevinlul avatar Feb 16 '23 05:02 kevinlul

@kevinlul looks like a dependency issue!

Abhishek7Tech avatar Feb 16 '23 05:02 Abhishek7Tech

Unfortunately not a new issue :( https://github.com/discordjs/discord.js/issues/4095#issuecomment-988071918

JMTK avatar Feb 16 '23 18:02 JMTK

I see, so it's a rare incident that could occur with erlpack.

kevinlul avatar Feb 16 '23 22:02 kevinlul

No I think it's legitimately coming from some websocket event. If you don't use erlpack you get the same type of error but showing as null instead of a Zero length buffer https://github.com/discordjs/discord.js/issues/4095#issuecomment-1211499512

IMO the library should handle these and return early, I've had to add in a special case to ignore these in my event handler. My assumption is it's coming from a new websocket version or server being setup on Discord's end

JMTK avatar Feb 17 '23 03:02 JMTK

Maybe Discord shouldn't send garbage down the pipe 😕

kevinlul avatar Feb 17 '23 04:02 kevinlul

This could just be an issue on our end where we don't renew the Inflate at the right time in some specific cases, y'know?

I do wonder if anyone is able to reproduce this on @discordjs/ws/the migration to it will fix this.

didinele avatar Feb 17 '23 05:02 didinele

The underlying WS internals have changed entirely. Please make a new issue if you re-encounter this issue on newer versions of the library.

didinele avatar Jan 22 '24 09:01 didinele