Nabrok / gw2-discord-bot

Discord bot for the Guild Wars 2 API.
GNU General Public License v3.0
33 stars 25 forks source link

Unhandled "error" event causes bot service to crash #31

Open myurkoski opened 6 years ago

myurkoski commented 6 years ago

This just started happening once a day early in the morning. Bot runs fine, then crashed with the following outputs and stacktrace:

Jan 24 00:39:31 files npm[1022]: events.js:188
Jan 24 00:39:31 files npm[1022]:       throw err;
Jan 24 00:39:31 files npm[1022]:       ^
Jan 24 00:39:31 files npm[1022]: Error: Unhandled "error" event. ([object Object])
Jan 24 00:39:31 files npm[1022]:     at Client.emit (events.js:186:19)
Jan 24 00:39:31 files npm[1022]:     at WebSocketConnection.onError (/Drive1/Games/Discord_GW2_bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:371:17)
Jan 24 00:39:31 files npm[1022]:     at WebSocket.onError (/Drive1/Games/Discord_GW2_bot/node_modules/ws/lib/event-target.js:128:16)
Jan 24 00:39:31 files npm[1022]:     at emitOne (events.js:116:13)
Jan 24 00:39:31 files npm[1022]:     at WebSocket.emit (events.js:211:7)
Jan 24 00:39:31 files npm[1022]:     at WebSocket.finalize (/Drive1/Games/Discord_GW2_bot/node_modules/ws/lib/websocket.js:190:41)
Jan 24 00:39:31 files npm[1022]:     at emitOne (events.js:116:13)
Jan 24 00:39:31 files npm[1022]:     at TLSSocket.emit (events.js:211:7)
Jan 24 00:39:31 files npm[1022]:     at emitErrorNT (internal/streams/destroy.js:64:8)
Jan 24 00:39:31 files npm[1022]:     at _combinedTickCallback (internal/process/next_tick.js:138:11)
Jan 24 00:39:31 files npm[1022]:     at process._tickCallback (internal/process/next_tick.js:180:9)
Jan 24 00:39:31 files npm[1022]: npm ERR! code ELIFECYCLE
Jan 24 00:39:31 files npm[1022]: npm ERR! errno 1
Jan 24 00:39:31 files npm[1022]: npm ERR! discord_bot@1.0.0 start: `node discord_bot.js`
Jan 24 00:39:31 files npm[1022]: npm ERR! Exit status 1
Jan 24 00:39:31 files npm[1022]: npm ERR!
Jan 24 00:39:31 files npm[1022]: npm ERR! Failed at the discord_bot@1.0.0 start script.
Jan 24 00:39:31 files npm[1022]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Jan 24 00:39:31 files npm[1022]: ┌──────────────────────────────────────────────────────────────┐
Jan 24 00:39:31 files npm[1022]: │                   npm update check failed                    │
Jan 24 00:39:31 files npm[1022]: │             Try running with sudo or get access              │
Jan 24 00:39:31 files npm[1022]: │             to the local update config store via             │
Jan 24 00:39:31 files npm[1022]: │ sudo chown -R $USER:$(id -gn $USER) /home/Discordbot/.config │
Jan 24 00:39:31 files npm[1022]: └──────────────────────────────────────────────────────────────┘
Jan 24 00:39:31 files systemd[1]: GW2_Discordbot.service: Main process exited, code=exited, status=1/FAILURE
Jan 24 00:39:31 files systemd[1]: GW2_Discordbot.service: Unit entered failed state.
Jan 24 00:39:31 files systemd[1]: GW2_Discordbot.service: Failed with result 'exit-code'.

node --version results in v8.9.4

I believe there was a node.js update rolled out in the last couple days that could be related, though node.js is alien to me so I wouldn't know where to look for more details.

Please let me know if there is any other information that I can gather.

Nabrok commented 6 years ago

Is this happening every time you try to start the bot?

myurkoski commented 6 years ago

No, strangely it happens after the bot has been running for nearly 24 hrs, happily servicing peoples requests the entire time.

If you would like, I can post a longer log dump, which will include logging from when I fired it up, as well as the other failure to date.

Walavouchey commented 6 years ago

Looking at the code where the error event was emitted from, (discord.js/src/client/websocket/WebSocketConnection.js/371:17) it's described as "Emitted whenever the client's WebSocket encounters a connection error."

I'm no expert on this, but I suppose if connection errors are unhandled, you need to handle them yourself. It's simply a connection issue, so you don't need to post a longer log dump. You need to either have a fully stable internet or find a way to make it reconnect automatically.

If a connection error occurs after 24 hours, it's likely just your internet having some sort of timeout.