node-mysql2
node-mysql2 copied to clipboard
ER_CON_COUNT_ERROR - Promise pool query not release correctly ?
I am making a script that reverses a series of IP addresses. For each list of IP addresses, i add the IP addresses in my DB via a query. I am using a multiworker system and the mysql pool system but I am facing a problem. I have the impression that once the query is finished, it does not release the connection. Because after a while I get "ER_CON_COUNT_ERROR" (too much connection) and is not possible because I'm using only 4 concurrent worker.
Do you have any idea ?
cidrCalculator(cidr).then((value,error) => {
value.forEach(element => {
promises.push(reverse(element[0]).then((result, error) => {
var sql = `INSERT IGNORE INTO domain(ip,address) VALUES (?)`;
pool.promise().query(sql, [[element[0],result[0]]])
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
if(err) throw err;
}).finally(() => {
});
}).catch((e) => {
//console.log(e);
}));
});
Promise.all(promises).then(() => {
parentPort.postMessage(true);
console.log('\x1b[32m%s\x1b[0m',`Worker ${workerData.workerIndex}/${workerData.cidrListsLength} - FINISH`);
});
}).catch(error => {
console.error('caught error!', error)
}).finally(() => {});
node:internal/event_target:777
process.nextTick(() => { throw err; });
^
Error: Trop de connexions
at PromisePool.query (C:\Users\Quentin Gosset\Desktop\devtz\node_modules\mysql2\promise.js:341:22)
at C:\Users\Quentin Gosset\Desktop\devtz\cidr\worker.js:32:36
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Promise.all (index 27)
Emitted 'error' event on Worker instance at:
at Worker.[kOnErrorMessage] (node:internal/worker:289:10)
at Worker.[kOnMessage] (node:internal/worker:300:37)
at MessagePort.<anonymous> (node:internal/worker:201:57)
at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:562:20)
at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28) {
code: 'ER_CON_COUNT_ERROR',
errno: 1040,
sql: undefined,
sqlState: '',
sqlMessage: 'Trop de connexions'
}
try to set lower connectionLimit - https://github.com/mysqljs/mysql#pool-options