From b053bc61ce099eab8d8b8fe30317f03f39a5833c Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Thu, 17 Nov 2022 18:34:02 +0000 Subject: [PATCH] Fixed MySQL monitor to close connection Signed-off-by: Matthew Nickson --- server/util-server.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index 7d271e85..701d61e6 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -13,7 +13,7 @@ const { badgeConstants } = require("./config"); const mssql = require("mssql"); const { Client } = require("pg"); const postgresConParse = require("pg-connection-string").parse; -const mysql = require("mysql2/promise"); +const mysql = require("mysql2"); const { NtlmClient } = require("axios-ntlm"); const { Settings } = require("./settings"); const radiusClient = require("node-radius-client"); @@ -300,16 +300,16 @@ exports.postgresQuery = function (connectionString, query) { */ exports.mysqlQuery = function (connectionString, query) { return new Promise((resolve, reject) => { - return mysql.createConnection(connectionString) - .then(connection => { - connection.connect(); - return connection.query(query); - }) + const connection = mysql.createConnection(connectionString); + connection.promise().query(query) .then(res => { resolve(res); }) .catch(err => { reject(err); + }) + .finally(() => { + connection.end(); }); }); };