Skip to content
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

Bot frequently stops due to unhandled error event #29

Open
yokuyuki opened this issue Jul 20, 2018 · 15 comments
Open

Bot frequently stops due to unhandled error event #29

yokuyuki opened this issue Jul 20, 2018 · 15 comments

Comments

@yokuyuki
Copy link

The stacktrace contains:

events.js:188
      throw err;
      ^

Error: Unhandled "error" event. ([object Object])
    at Client.emit (events.js:186:19)
    at WebSocketConnection.onError (/home/yokuyuki/spoilerbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
    at WebSocket.onError (/home/yokuyuki/spoilerbot/node_modules/discord.js/node_modules/ws/lib/event-target.js:128:16)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at WebSocket.finalize (/home/yokuyuki/spoilerbot/node_modules/discord.js/node_modules/ws/lib/websocket.js:185:12)
    at ClientRequest._req.on (/home/yokuyuki/spoilerbot/node_modules/discord.js/node_modules/ws/lib/websocket.js:641:12)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:551:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:115:23)
    at TLSSocket.socketOnData (_http_client.js:440:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
@TimboKZ
Copy link
Owner

TimboKZ commented Jul 20, 2018

Interesting, not sure how easy it will be to reproduce.

How are you running the bot? Are you passing in an external bot instance?

@yokuyuki
Copy link
Author

I have it set up in the same way as specified in basic usage. If I leave the bot running all the time, it happens once a week when I notice the bot has left the channel because it is killed due to the above error.

@TimboKZ
Copy link
Owner

TimboKZ commented Jul 20, 2018

Fair enough, will take a look later today.

Meanwhile you might wanna use a process manager like pm2 to automatically restart the bot after it crashes.

@yokuyuki
Copy link
Author

yokuyuki commented Jul 20, 2018

Based on discordjs/discord.js#2523 it seems like maybe client just need to handle the error. Maybe something as simple as client.on('error', log.error). Thanks for the tip about the process manager though.

@Taelkir
Copy link

Taelkir commented Sep 28, 2018

Did adding client.on('error', log.error) prevent the issue happening again for you? I added something like that to my bot a few weeks ago and I'm still getting the error you described on a regular basis

@TimboKZ TimboKZ added the bug label Sep 30, 2018
@GuimDev
Copy link

GuimDev commented Oct 3, 2018

Do you have an idea about the origin ?

@XenHat
Copy link

XenHat commented Nov 5, 2018

I'm also having this issue, when using the bot by passing it to an external instance.
It seems to happen pretty reliably when sending spoiler creation requests through <post>:spoils:<topic> more than once every 5 seconds, although it still crashes if I want more (10, 15 seconds)

EDIT: I ran the bot standalone and I am also experiencing these issues:

[Nov 5, 2018, 20:27] Discord Spoiler Bot is running!
[Nov 5, 2018, 20:27] Processed 'Test' spoiler from XenHat.
[Nov 5, 2018, 20:27] Processed 'Test' spoiler from XenHat.
[Nov 5, 2018, 20:27] Processed 'Test' spoiler from XenHat.

Then it died.
The input text was: Test:spoiler:A Test!

Adding client.on('error'... in various places did not produce any output, either I did not put the code in the right function, or it's not catching anything.

I also tried hooking the node instance to Google Chrome in debugging mode, and nothing new came out of that either.

@Gravitygrey
Copy link

Gravitygrey commented Jan 6, 2019

It's from the computer/bot going idle, it stops its self from just being on all the time... This may just be discord kicking you offline also from your bot not being used... Try adding a small thing that makes your bot want to always do something like show it typing on a text server every 5 min or so... Also, if this doesn't work try moving your bot to a host (I don't recommend glitch) or buy a Raspberry Pi 3b for like $35 and run it on that... I'm about to make the change to the pi here soon knowing the pi will keep it running.... I don't recommend running your bot on your computer either because you might not have the hardware rated for 24/7 usage like me (my read and write speeds are now cut to a small percentage of what it used to be and the ram was always bad on this computer)

Edit/Summary:
its not really a bug either way... just make your computer not turn off or the bot go inactive for a bit or read above and check other options...

@yokuyuki
Copy link
Author

yokuyuki commented Jan 8, 2019

@Gravitygrey already running it on a host so that's not the issue. I mostly got around it using pm2 to restart the bot so for the most part it's not noticeable now, but I don't think that's an actual fix to the issue.

@ipadpuppydogdude1
Copy link

It's your computer being disconnected from wifi, simple.

@Thedude7054
Copy link

Can we get some light shed on this? This is still a problem for many of us in the community.

@AzureeDev
Copy link

AzureeDev commented Mar 3, 2019

Hi,

What you can do is a simple change in node_modules/discord.js/src/client/websocket/WebSocketConnection.js

Line 364, change the whole function onError(err) to:

onError(error) {
    if (error && error.message === 'uWs client connection error') {
      this.reconnect();
      return;
    }

    this.reconnect();
    return;
  }

Which will force a connection instead of crashing on that error.

@Swifty2019
Copy link

this fixed my problem. I slightly altered mwSora's version -- this.reconnect() errored out for me

client.on('error', error => {
if (error && error.message === 'uWs client connection error') {
this.reconnect();
return;
}
});

@XenHat
Copy link

XenHat commented Dec 23, 2019

Can we get some light shed on this? This is still a problem for many of us in the community.

Yes, as other said, after my own investigations and asking a few other devs, this is a problem with discord.js timing/erroring out on some long-time connections. Simply catching the error and forcing the client to reconnect/restart will resolve the issue.

Another (less helpful) way to say this is "upstream issue".

@TimboKZ
Copy link
Owner

TimboKZ commented Dec 26, 2019

Hi people, can I ask you what are you using the bot for?

I think built-in spoiler functionality covers all use cases, or am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants