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