I have a query
function that takes an sql and executes it, like this:
import mariadb, { QueryOptions } from "mariadb";
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
acquireTimeout: 30000,
connectTimeout: 10000,
idleTimeout: 60000,
});
export async function query(sql: string | QueryOptions, values?: Array<unknown>) {
let conn;
try {
console.log("Attempting to get a connection from the pool...");
conn = await pool.getConnection();
console.log(`Connection acquired. Active connections: ${pool.activeConnections()}, Idle connections: ${pool.idleConnections()}`);
console.log("Executing query...");
const rows = await conn.query(sql, values);
console.log("Query executed successfully:", rows);
return rows;
} catch (e) {
console.error("Error executing query:", e);
throw e;
} finally {
if (conn) {
console.log("Releasing connection back to the pool...");
await conn.release();
console.log(`Connection released. Active connections: ${pool.activeConnections()}, Idle connections: ${pool.idleConnections()}`);
}
}
}
process.on("SIGINT", async () => {
console.log("Closing database pool...");
await pool.end();
process.exit(0);
});
However, it just kills itself and throws a timeout error every few minutes. Can anyone help me?