Closed pkdev08 closed 3 weeks ago
Please provide a reproducible sample! Also, can you try reproducing this on a development version?
Please provide a reproducible sample! Also, can you try reproducing this on a development version?
This doesn't happen very frequently, so it will be hard to reproduce. It happens randomly after the bot has been up for a while. Yes, tried on dev version. The issue isn't the actual 520 response error, but the Uncaught exception part.
+1 on this; it happens to my sharded bot without any repro steps other than waiting and watching the console log. Additionally, instead of
error: Error: Unexpected server response: 520
I get both authentication failed and "sharding is required" errors
Would be useful if you could at least tell us how you're instantiating your client.
I use the information/code from both the documentation and guide
No one in this issue has ever mentioned the ShardingManager. That's probably related. I'll try to investigate this week
Gotcha, my bad. I'll provide more of my logs for reference. I did some more digging and it looks like this is happening right after a zombie connection is identified
0|main | [WS => Shard 0] Destroying shard 0|main | Reason: Zombie connection 0|main | Code: 4200 0|main | Recover: Resume 0|main | [WS => Shard 0] Connection status during destroy 0|main | Needs closing: false 0|main | Ready state: 3
Authentication required:
0|main | Caught exception: Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed 0|main | Exception origin: uncaughtException 0|main | Unhandled Rejection at: Promise { 0|main | <rejected> Error: Unhandled 'error' event emitted, received [object Object] 0|main | at WebSocketShard.emit (/root/aphrodite/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:276:19) 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1102:14) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 { 0|main | context: { 0|main | error: Error: Authentication failed 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1103:18) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 0|main | at TCP.done (node:_tls_wrap:631:7) 0|main | } 0|main | } 0|main | } reason: Error: Unhandled 'error' event emitted, received [object Object] 0|main | at WebSocketShard.emit (/root/aphrodite/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:276:19) 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1102:14) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 { 0|main | context: { 0|main | error: Error: Authentication failed 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1103:18) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 0|main | at TCP.done (node:_tls_wrap:631:7) 0|main | } 0|main | }
Sharding required (despite being sharded):
0|main | Unhandled Rejection at: Promise { 0|main | <rejected> Error: Unhandled 'error' event emitted, received [object Object] 0|main | at WebSocketShard.emit (/root/aphrodite/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:276:19) 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1130:14) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 { 0|main | context: { 0|main | error: Error: Sharding is required 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1131:18) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 0|main | at TCP.done (node:_tls_wrap:631:7) 0|main | } 0|main | } 0|main | } reason: Error: Unhandled 'error' event emitted, received [object Object] 0|main | at WebSocketShard.emit (/root/aphrodite/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:276:19) 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1130:14) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 { 0|main | context: { 0|main | error: Error: Sharding is required 0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1131:18) 0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17) 0|main | at callListener (/root/aphrodite/node_modules/ws/lib/event-target.js:290:14) 0|main | at WebSocket.onClose (/root/aphrodite/node_modules/ws/lib/event-target.js:220:9) 0|main | at WebSocket.emit (node:events:514:28) 0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/ws/lib/websocket.js:272:10) 0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/ws/lib/websocket.js:1341:15) 0|main | at TLSSocket.emit (node:events:526:35) 0|main | at node:net:337:12 0|main | at TCP.done (node:_tls_wrap:631:7) 0|main | } 0|main | }
Happy to provide more info whenever you investigate if needed. Thank you!
I am receiving this same error with @discordjs/core
this error is being throw on startup
/var/www/html/bot/node_modules/@vladfrangu/async_event_emitter/src/index.ts:346
const err = new Error(`Unhandled 'error' event emitted, received ${stringifiedError}`);
^
Error: Unhandled 'error' event emitted, received [object Object]
at WebSocketManager.emit (/var/www/html/bot/node_modules/@vladfrangu/async_event_emitter/src/index.ts:346:16)
at WebSocketShard.<anonymous> (/var/www/html/bot/node_modules/@discordjs/ws/src/strategies/sharding/SimpleShardingStrategy.ts:32:47)
at WebSocketShard.emit (/var/www/html/bot/node_modules/@vladfrangu/async_event_emitter/src/index.ts:371:33)
at WebSocketShard.onClose (/var/www/html/bot/node_modules/@discordjs/ws/src/ws/WebSocketShard.ts:814:10)
at WebSocket.connection.onclose (/var/www/html/bot/node_modules/@discordjs/ws/src/ws/WebSocketShard.ts:203:14)
at callListener (/var/www/html/bot/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onClose (/var/www/html/bot/node_modules/ws/lib/event-target.js:220:9)
at WebSocket.emit (node:events:519:28)
at WebSocket.emitClose (/var/www/html/bot/node_modules/ws/lib/websocket.js:265:10)
at TLSSocket.socketOnClose (/var/www/html/bot/node_modules/ws/lib/websocket.js:1289:15)
and was throwing when my intents were wrong.
I am receiving this same error with
@discordjs/core
this error is being throw on startup/var/www/html/bot/node_modules/@vladfrangu/async_event_emitter/src/index.ts:346 const err = new Error(`Unhandled 'error' event emitted, received ${stringifiedError}`); ^ Error: Unhandled 'error' event emitted, received [object Object] at WebSocketManager.emit (/var/www/html/bot/node_modules/@vladfrangu/async_event_emitter/src/index.ts:346:16) at WebSocketShard.<anonymous> (/var/www/html/bot/node_modules/@discordjs/ws/src/strategies/sharding/SimpleShardingStrategy.ts:32:47) at WebSocketShard.emit (/var/www/html/bot/node_modules/@vladfrangu/async_event_emitter/src/index.ts:371:33) at WebSocketShard.onClose (/var/www/html/bot/node_modules/@discordjs/ws/src/ws/WebSocketShard.ts:814:10) at WebSocket.connection.onclose (/var/www/html/bot/node_modules/@discordjs/ws/src/ws/WebSocketShard.ts:203:14) at callListener (/var/www/html/bot/node_modules/ws/lib/event-target.js:290:14) at WebSocket.onClose (/var/www/html/bot/node_modules/ws/lib/event-target.js:220:9) at WebSocket.emit (node:events:519:28) at WebSocket.emitClose (/var/www/html/bot/node_modules/ws/lib/websocket.js:265:10) at TLSSocket.socketOnClose (/var/www/html/bot/node_modules/ws/lib/websocket.js:1289:15)
and was throwing when my intents were wrong.
Your "issue" is most certainly caused by not having an error listener on the manager, looking at your stack trace. As per intents, that is intended to throw an error you cannot catch.
The folks in this issue do have an error listener, which makes the hard error unexpected behavior.
No one in this issue has ever mentioned the ShardingManager. That's probably related. I'll try to investigate this week
I'm not using the ShardingManager, just internal sharding. Instantiated the client like this:
const client = new Client({
shards: 'auto'
});
Not sure if this helps, but the last time this error emitted through shardError
was on 7/2/24 and also the 520
response errors started on 5/19/24.
This is how it was emitted before, and it would close with a 1006
and resume and replay the events.
Shard with the ID of 63 encountered an error: Error: Unexpected server response: 520
Hey there, as stated in https://github.com/discordjs/discord.js/issues/10392#issuecomment-2229468291 - this is an upstream bug, hence why it was weirdly introduced even to discord.js
despite not getting /ws
updated in ages. A fix is coming out shortly to that package.
Does this mean my issue is something entirely separate? So sorry, very tired today 🥲
Does this mean my issue is something entirely separate? So sorry, very tired today 🥲
I'm not sure! 520 is normal. The Shard should be catching it, but async_event_emitter was wrongly throwing the error despite a error
listener being attached, so it should now be fixed.
@vladfrangu/async_event_emitter@2.4.4
is now out, so please force it to update and see if it still causes trouble - this goes for everyone in this thread.
I'm not sure what the "proper" way of forcing a non-direct dep like that to update is, but for sure wiping your node_modules
and lock file and rerunning npm i
/yarn
/pnpm i
will be enough.
Unfortunately, no 😭 I just force removed everything and reinstalled and got this big ol error a few mins in:
0|main | Exception origin: uncaughtException
0|main | Unhandled Rejection at: Promise {
0|main | <rejected> Error: Unhandled 'error' event emitted, received [object Object]
0|main | at WebSocketShard.emit (/root/aphrodite/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:276:19)
0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1102:14)
0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17)
0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14)
0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9)
0|main | at WebSocket.emit (node:events:514:28)
0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10)
0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15)
0|main | at TLSSocket.emit (node:events:526:35)
0|main | at node:net:337:12 {
0|main | context: {
0|main | error: Error: Authentication failed
0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1103:18)
0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17)
0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14)
0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9)
0|main | at WebSocket.emit (node:events:514:28)
0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10)
0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15)
0|main | at TLSSocket.emit (node:events:526:35)
0|main | at node:net:337:12
0|main | at TCP.done (node:_tls_wrap:631:7)
0|main | }
0|main | }
0|main | } reason: Error: Unhandled 'error' event emitted, received [object Object]
0|main | at WebSocketShard.emit (/root/aphrodite/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:276:19)
0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1102:14)
0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17)
0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14)
0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9)
0|main | at WebSocket.emit (node:events:514:28)
0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10)
0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15)
0|main | at TLSSocket.emit (node:events:526:35)
0|main | at node:net:337:12 {
0|main | context: {
0|main | error: Error: Authentication failed
0|main | at WebSocketShard.onClose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:1103:18)
0|main | at connection.onclose (/root/aphrodite/node_modules/@discordjs/ws/dist/index.js:686:17)
0|main | at callListener (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:290:14)
0|main | at WebSocket.onClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/event-target.js:220:9)
0|main | at WebSocket.emit (node:events:514:28)
0|main | at WebSocket.emitClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:272:10)
0|main | at TLSSocket.socketOnClose (/root/aphrodite/node_modules/@discordjs/ws/node_modules/ws/lib/websocket.js:1341:15)
0|main | at TLSSocket.emit (node:events:526:35)
0|main | at node:net:337:12
0|main | at TCP.done (node:_tls_wrap:631:7)
0|main | }
0|main | }
Sorry in advance for the formatting of the comment, I don't know why it's not line spacing correctly lol
Can you run npm ls @vladfrangu/async_event_emitter
(or yarn why
, etc) and let us know the version? 2.4.4 has the fix for this, 👀 (unless you dont have a listener yourself for error events on the manager)
No problem!
I do have my own listeners for it and for some reason this error is just throwing itself everywhere and burning through my sessions
We're a bit confused on the stack trace, but for now, that error is only thrown if Discord themselves think something is wrong with your auth token. Please make sure the bot token you are passing in is still valid.
I double checked, it's the correct token since I just replaced it with a new one this morning; it used all its sessions
If this helps, I just found these logs that happen directly before each time the unhandled error event emits -
[WS => Shard 1] Destroying shard
0|main | Reason: Zombie connection
0|main | Code: 4200
0|main | Recover: Resume
0|main | [WS => Shard 1] Connection status during destroy
0|main | Needs closing: false
0|main | Ready state: 3
0|main | [WS => Shard 10] Heartbeat acknowledged, latency of 73ms.
0|main | [WS => Shard 1] Connecting to wss://gateway.discord.gg?v=10&encoding=json
0|main | [WS => Shard 1] Waiting for event hello for 60000ms
0|main | [WS => Shard 1] Preparing first heartbeat of the connection with a jitter of 0.518201557876262; waiting 21375ms
0|main | [WS => Shard 1] Waiting for identify throttle
0|main | [WS => Shard 1] Identifying
0|main | shard id: 1
0|main | shard count: 23
0|main | intents: 33411
0|main | compression: none
0|main | [WS => Shard 1] Waiting for event ready for 15000ms
0|main | Caught exception: Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
Thanks y'all for looking into this 🥺
Which package is this bug report for?
discord.js
Issue description
Getting error
Unhandled 'error' event emitted, received [object Object]
although listening to botherror
andshardError
event. Iv'e gotten this 520 response error before, but it used to always emit to theshardError
event before14.15.3
Code sample
No response
Versions
Issue priority
Medium (should be fixed soon)
Which partials do you have configured?
Channel, GuildMember, Message, Reaction
Which gateway intents are you subscribing to?
Not applicable
I have tested this issue on a development release
No response