Всем привет, устал уже от этой ошибки может тут поможете решить? Что в нём не так?
Непосредственно ошибка
Error: connect ETIMEDOUT
at PoolConnection.Connection._handleConnectTimeout (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\Connection.js:409:13)
at Object.onceWrapper (events.js:420:28)
at Socket.emit (events.js:314:20)
at Socket._onTimeout (net.js:482:8)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
--------------------
at Protocol._enqueue (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\Pool.js:48:16)
at Object.mysql.executeQuery (C:\Users\crazy\Desktop\larp\larp-server\packages\modules\mysql.js:207:14)
at init (C:\Users\crazy\Desktop\larp\larp-server\packages\index.js:68:15)
at Object.<anonymous> (C:\Users\crazy\Desktop\larp\larp-server\packages\index.js:146:1)
at Module._compile (internal/modules/cjs/loader.js:1076:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:941:32) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
at processTimers (internal/timers.js:497:7)
--------------------
at Protocol._enqueue (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Users\crazy\Desktop\larp\larp-server\node_modules\mysql\lib\Pool.js:202:8)
at Object.mysql.executeQueryOld (C:\Users\crazy\Desktop\larp\larp-server\packages\modules\mysql.js:244:14)
at Object.mysql.executeQuery (C:\Users\crazy\Desktop\larp\larp-server\packages\modules\mysql.js:198:19)
at Object.vehicleInfo.loadAll (C:\Users\crazy\Desktop\larp\larp-server\packages\modules\vehicleInfo.js:8:11)
at init (C:\Users\crazy\Desktop\larp\larp-server\packages\index.js:73:21)
at Object.<anonymous> (C:\Users\crazy\Desktop\larp\larp-server\packages\index.js:146:1) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
Сам код
const pool = mysql2.createPool({
host: host,
//socketPath: '/var/run/mysqld/mysqld.sock', //Если хочешь напрямую по сокету подключать, ускоряет немного всю хуйню
user: dbuser,
password: password,
database: database,
port: 3306,
waitForConnections: true,
connectionLimit: 500,
queueLimit: 0
});
pool.on('connection', function (connection) {
connection.query("SET SESSION `sql_mode` = ''");
connection.query("SET GLOBAL `connect_timeout` = '31536000'");
connection.query("SET GLOBAL `wait_timeout` = '31536000'");
connection.query("SET GLOBAL `interactive_timeout` = '28800'");
console.log('New MySQL connection id: ' + connection.threadId);
});
mysql.executeQuery = async function (query, values, callback) {
const preQuery = new Date().getTime();
try {
if (query.indexOf('DELETE') === 0 /*|| query.indexOf('UPDATE') === 0*/ || query.indexOf('INSERT') === 0 || query.indexOf('SELECT') === 0) {
mysql.executeQueryOld(query, values, function (err, rows, fields) {
try {
if (callback)
callback(err, rows, fields);
}
catch (e) {}
});
return;
}
pool.getConnection(function (err, connection) {
try {
if(!err) {
connection.query({
sql: query
}, values, function (err, rows, fields) {
const postQuery = new Date().getTime();
methods.debug(query, `Async time: ${postQuery - preQuery}ms`);
try {
if (!err) {
if (callback)
callback(null, rows, fields);
} else {
console.log("[DATABASE ASYNC | ERROR | " + mysql.getTime() + "]", query, err);
if (callback)
callback(err);
}
}
catch (e) {}
});
}
else throw err;
connection.release();
}
catch (e) {
console.log(e);
}
});
} catch (e) {
console.log('DBERROR', e);
}
};