#Bot Crashing with no error?

8 messages · Page 1 of 1 (latest)

dull canopy
#

Here's the issue: In the past, my bot was written in TypeScript and using MongoDB. Well, i've been trying to add a Web Panel to the bot so configuration doesnt have to happen by commands anymore, and the backend using the database doesnt have the best support for MongoDB. So i tried to move over to MySQL. MySQL works fine, until my bot decides to stop working. And by that i mean this: The bot will stay online, but any functions that use the Database just quit working.

This is the Code that creates a database connection based on the credentials i have in another file

import mysql from 'mysql2/promise';
import { web } from "../../config/webconfig";

const config = {
    host: web.mysql_host,
    user: web.mysql_user,
    password: web.mysql_pass,
    database: web.mysql_database,
};

export const pool = mysql.createPool(config);
setInterval(logMySQLConnectionStatus, 60 * 60 * 1000);
// Function to get a connection from the pool
export const getConnection = async () => {
    return await pool.getConnection();
};

export async function logMySQLConnectionStatus() {
    try {
      // Check the MySQL connection status
      const [rows] = await pool.execute('SELECT 1') as any; // Destructure the result to get 'rows'
  
      if (rows && rows.length > 0) {
        console.log('MySQL connection is active at', new Date().toLocaleString());
      } else {
        console.log('MySQL connection is not active at', new Date().toLocaleString());
      }
    } catch (error) {
      console.error('Error checking MySQL connection:', error);
    }
  }

The issue is that the bot doesnt send any error codes whenever it does quit functioning as expected. It just stops responding to any commands/events using the database. What i've noticed is that the bot will stop working correctly after about 80-90 minutes of being online. I tried to ask the same question on StackOverflow, but they said that they cant help unless i have an error i can show them. The issue is that the bot wont give any errors when it stops functioning as expected. So now im curious if this is just an issue with the mysql2 driver from npm, considering only the commands using the database stop working

tame flare
#

do you release connections anywhere?

dull canopy
#

every command and event releases the connection

#

when its done using it

#

For instance:

import { CommandInteraction, Client, EmbedBuilder } from "discord.js";
import { getConnection } from '../../functions/database/connectDatabase';

export default {
    name: "website",
    description: "Retrieves Website Link",
    run: async (client: Client, interaction: CommandInteraction) => {
        try {
            const guildId = interaction.guild?.id;
            if (!guildId) {
                return;
            }

            const connection = await getConnection();
                const [customRows] = await connection.query("SELECT mastercolor FROM cfg_misc WHERE guild_id = ?", [guildId]) as any;
            connection.release();

            const embedColor = customRows[0]?.mastercolor
            const infoEmbed = new EmbedBuilder()
                .setColor(embedColor)
                .setTitle(`Website Link`)
                .addFields({ name: 'Website Name:', value: `SystemdBot Web Panel`})
                .addFields({ name: 'Website Link:', value: `https://systemdbot.com`})
                .setThumbnail(client.user?.displayAvatarURL() as any)
                .setTimestamp();
                            
            interaction.reply({ embeds: [infoEmbed] });
        } catch(error) {
            console.error(error);
        }
    }
}
tame flare
#

when the query errors, the connection doesnt get released and eventually the pool is full -> "stops working"

dull canopy
#

i do notice that there are 12 sleeping processes under the user that the bot connects to to access the database. I dont know if that is related to the issues im having

#

Holy crap, thats what it is