System Information
- Strapi Version: 4.4.3
- Operating System:
- Database: postgres
- Node Version:
- NPM Version:
- Yarn Version:
Hi everyone,
Every second I get info from a messaging service (XMPP) and I need to store this info in my database.
Here is my code:
function updateFeux(feuxList) { //feuxlist.lenght = 2000
let startTime = new Date()
for (let i = 0; i < feuxList.length; i++) {
strapi.db
.query('api::feu.feu')
.updateMany({
where: {
id_carrefour: feuxList[i].id_carrefour,
id_feu: feuxList[i].id_feu,
},
data: {
feu: feuxList[i].feu,
},
})
.then(
i == feuxList.length - 1
? logInFile(
'DB',
'FEU : ' +
feuxList.length +
' ROWS ARE BEIN UPDATED IN : ' +
Math.abs((new Date().getTime() - startTime.getTime()) / 1000) +
' SECONDS',
)
: '',
)
.catch(console.error)
}
}
But after a while I get this error:
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The
promise rejected with the reason:
KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
at Client_PG.acquireConnection (C:\Users\PC-VOLANT\Documents\Depot_git\API_GTR\node_modules\knex\lib\client.js:310:26)
at runNextTicks (node:internal/process/task_queues:61:5)
at listOnTimeout (node:internal/timers:528:9)
at processTimers (node:internal/timers:502:7)
at async Runner.ensureConnection (C:\Users\PC-VOLANT\Documents\Depot_git\API_GTR\node_modules\knex\lib\execution\runner.js:294:28)
at async Runner.run (C:\Users\PC-VOLANT\Documents\Depot_git\API_GTR\node_modules\knex\lib\execution\runner.js:30:19)
at async Object.execute (C:\Users\PC-VOLANT\Documents\Depot_git\API_GTR\node_modules\@strapi\database\lib\query\query-builder.js:396:22)
at async Object.updateMany (C:\Users\PC-VOLANT\Documents\Depot_git\API_GTR\node_modules\@strapi\database\lib\entity-manager\index.js:279:27)
My technical director told me that this error occurred when we opened too many connections to postgres, I tried in “database.js” to increase the value “max” in the object “pool” but it does not work.
So I thought about it and I say to myself when in reality it has not finished doing the update that I re-call my “updateFeux()” function, is that right?
How I can solve this ?
Thanks