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

Discord Bot loses connection to server after a period of time and has to be restarted #4

Open
entropiccode opened this issue Sep 12, 2022 · 5 comments

Comments

@entropiccode
Copy link

I'm uncertain if this is an issue with the bot itself or my setup.
After the bot has been started, all the commands are fully functional. However, after a period of inactivity (seems to be a few hours), the bot seems to lose connection to the server. The loss of connection is not noticed until another command is sent to the bot, at which time the bot will respond with the following error:
There was an error trying to execute that command!

This is the output printed to the console:

Error: Can't add new command when connection is in closed state
    at Connection._addCommandClosedState (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql2/lib/connection.js:148:17)
    at Connection.query (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql2/lib/connection.js:546:17)
    at Object.execute (/opt/warcraft/AzerothCoreDiscordBot/commands/online.js:14:16)
    at Client.<anonymous> (/opt/warcraft/AzerothCoreDiscordBot/server.js:72:65)
    at Client.emit (node:events:527:28)
    at MessageCreateAction.handle (/opt/warcraft/AzerothCoreDiscordBot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/opt/warcraft/AzerothCoreDiscordBot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/opt/warcraft/AzerothCoreDiscordBot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31) 
    at WebSocketShard.onPacket (/opt/warcraft/AzerothCoreDiscordBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/opt/warcraft/AzerothCoreDiscordBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10) {      
  fatal: true
}

The azerothcore server itself is a docker installation. My config.js is as follows:

module.exports = {

        token: "<redacted>",
        prefix: "!",
        statusMessage: "with my 25 characters!",
        color: "#0000FF",

        databaseHost: '127.0.0.1',
        databaseUser     : '<redacted>',
        databasePassword : '<redacted>',

        soapPort: 7878,
        soapHostname: "127.0.0.1",
        soapAuth: "<redacted>"

}

One other note is that the soapAuth user is the GM account I use when I need to perform GM functions. Would logging into that account cause the bot to disconnect, and is it recommended for the bot to have a dedicated GM account through which to authenticate with the server?

@XanderDeLaet
Copy link
Owner

XanderDeLaet commented Sep 13, 2022

Looks like a package issue with mysql2, could you try using mysql?

Do the following to try it:
Command in terminal: npm i mysql
Change in file databasesql.js: require('mysql2') --> require('mysql')

@entropiccode
Copy link
Author

Updated as recommended, I will follow up once I have been able to test if it disconnects automatically.

@XanderDeLaet
Copy link
Owner

Updated as recommended, I will follow up once I have been able to test if it disconnects automatically.

Any update on this?

@entropiccode
Copy link
Author

The connection definitely seems to be more stable, however I am still seeing some disconnects. I haven't had the opportunity to sit down and review the error messages yet, I will comment again once I'm at home and able to review the errors.

@entropiccode
Copy link
Author

node:events:505
      throw er; // Unhandled 'error' event
      ^

Error: Packets out of order. Got: 0 Expected: 2
    at Parser._tryReadPacketHeader (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Parser.js:470:15)
    at Parser.write (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Parser.js:33:29)
    at Protocol.write (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Socket.Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Emitted 'error' event on Connection instance at:
    at Connection._handleProtocolError (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/Connection.js:423:8)
    at Protocol.emit (node:events:527:28)
    at Protocol._delegateError (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Protocol.js:398:10)
    at Protocol.handleParserError (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Protocol.js:380:10)
    at Parser._tryReadPacketHeader (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Parser.js:478:10)
    at Parser.write (/opt/warcraft/AzerothCoreDiscordBot/node_modules/mysql/lib/protocol/Parser.js:33:29)
    [... lines matching original stack trace ...]
    at Socket.emit (node:events:527:28) {
  code: 'PROTOCOL_PACKETS_OUT_OF_ORDER',
  fatal: true
}

This is the error the bot is throwing now.

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

No branches or pull requests

2 participants