From 769317c0d70227ecd61b8aceca8a091ae08133c8 Mon Sep 17 00:00:00 2001 From: Galexion Date: Wed, 19 Jul 2023 13:13:39 -0400 Subject: [PATCH] HotFix: Fixing ECONNRESET for Artemis users. --- dbhandler.js | 22 +++++++++++----------- index.js | 6 +++++- readme.md | 1 + 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/dbhandler.js b/dbhandler.js index 2d6643a..49f9325 100644 --- a/dbhandler.js +++ b/dbhandler.js @@ -5,17 +5,13 @@ if (serverType === 0) { db = new sqlite3.Database(aquaSrvDir + '\\db.sqlite'); } const mysql = require('mysql'); -var con = mysql.createConnection(ArtConnSettings) - +//var con = mysql.createConnection(ArtConnSettings); +var pool = mysql.createPool(ArtConnSettings); +var con = undefined if (serverType === 1) { - con.connect((err) => { - if (err) { - console.error('Error connecting to MySQL database:', err); - process.exit() - return; - } - - console.log('Connected to MySQL database.'); + pool.getConnection(function(err, connection) { + if (err) throw err; // not connected! + con = connection; }); } @@ -41,6 +37,7 @@ async function getUserCount() { throw err }; resolve(JSON.parse(JSON.stringify(result)).length); + con.release(); }); }); } @@ -94,6 +91,7 @@ async function getUserData(req) { if (mUser) { // Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile. resolve(mUser); + con.release(); } else { reject(new Error('User not found')); } @@ -146,6 +144,7 @@ async function getExtId(req) { if (mUser) { // Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile. resolve(mUser); + con.release(); } else { reject(new Error('User not found')); } @@ -199,6 +198,7 @@ async function getUserScores(req) { } // Return a Response with all the Scores listed under that user. resolve(mUser) + con.release(); }) }); } @@ -228,7 +228,6 @@ async function getUserArea(req) { }); }); } else { - return new Promise((resolve, reject) => { con.query("SELECT * FROM aime.mai2_item_map", function (err, result, fields) { if (err) { @@ -250,6 +249,7 @@ async function getUserArea(req) { } // Return a Response with all the Scores listed under that user. resolve(mUser) + con.release(); }) }); } diff --git a/index.js b/index.js index 24d0c37..c0f5ec4 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ var indexRouter = require('./routes/index'); var apiRouter = require('./routes/api'); var config = require("./config.json"); -if (config.serverType === 0) { // Only run the image Importer when Aqua is active +if (config.serverType === 0) { // Only run the image Importer with aqua or when given Artemis Settings for it) const watcher = chokidar.watch(config.aquaSrvDir, { persistent: true }); @@ -62,6 +62,10 @@ if (config.serverType === 0) { // Only run the image Importer when Aqua is activ } else { console.log("Image Export Disabled. Check readme.md for details.") } +if(config.serverType === 1 && !config.ArtConnSettings.connectionLimit) { + console.error("You are Missing the `ConnectionLimit` setting. Please add and set it in config.json."); + process.exit(1); +} // readFileSync function must use __dirname get current directory // require use ./ refer to current directory. diff --git a/readme.md b/readme.md index 5a6b2a1..c158607 100644 --- a/readme.md +++ b/readme.md @@ -68,6 +68,7 @@ Create a `config.json` file and paste this in, with paths to your instance. "ArtImageImport": true, "ArtImageDirectory":"S:\\Artemis\\Server\\Image\\Directory", "ArtConnSettings": { + "connectionLimit": "2", "host":"192.168.smt.hng", "user":"MaiDXNet", "pass":"aSecurePassword"