New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled 'error' event: "WebSocket was closed before the connection was established" when client was connected and network goes down #7964
Comments
i don't think you even replugged the network again as you didn't mention it, so why would this be a bug? |
That's right, but the application shouldn't crash with an unhandled 'error' event. Expected behavior would be, that discord.js keeps trying to reestablish the connection, or that there is some chance to handle the error. Edit: I've updated the description above. |
I must ask, are you able to reproduce this with v14? We are attaching
And for reference, |
Same error with v14 (14.0.0-dev.1653091711-fdeac9d) Example code: const { Client, GatewayIntentBits } = require('discord.js');
const token = 'xxx';
async function main () {
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
],
});
client.on('debug', console.debug);
client.on('warn', console.warn);
client.on('error', console.error);
client.on('ready', () => console.log('ready'));
await client.login(token);
}
main(); Logs
|
Yeah, I see the issue now, prior to calling
Which removes all the listeners:
And because we are closing while the WS is in a connecting state, it emits an abortion error: https://github.com/websockets/ws/blob/a690791df31cede48e7bcbce9d56411483309246/lib/websocket.js#L283-L286 -> https://github.com/websockets/ws/blob/a690791df31cede48e7bcbce9d56411483309246/lib/websocket.js#L1031-L1056 At this line within the last function, ws.onerror would be called: But because we removed the listeners earlier (and they were the only one present), we were not able to handle them. We could perhaps move the cc: @vladfrangu |
ig it's related to #7581 |
Can't confirm without debugging (please use one!), but I suppose it's because this line is called: That does... complicate some things. We could |
umm, I don't think so. Why? Because during close code 4009 it won't execute the else block which has |
Changing to Logs
If I remove the call of Logs
|
@crycode-de You can download it from here |
@legendhimslef |
I just had this same error today using discord.js 13.8.0:
|
This was already patched in |
Thanks! |
same on 13.8.1 :(
|
steps to recreate? |
#8164 will fix it |
wait whats the point of silencing errors. We already have issues with socket hangups. |
u can read #8150 description |
|
"discord.js": "13.9.0",
|
@pedroricardo Do you have an error handler attached to your client? client.on('error', console.error); |
@iCrawl I do not have |
The stacktrace suggests that you are running 13.4.0 (or even older): Please make sure you are actually running |
@pedroricardo Additionally to the thing above, please also have an error handler like I showed. |
Which package is this bug report for?
discord.js
Issue description
Steps to reproduce:
Full log: log.txt
There seams to be no way to handle the WebSocket error event.
Expected behavior would be, that discord.js keeps trying to reestablish the connection, or that there is some chance to handle the error.
Came up with this, as my internet connection was gone away and my application using discord.js crashed with the above error.
Code sample
Package version
13.7.0
Node.js version
16.14.2
Operating system
Debian 10
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
Guilds
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered: