简体   繁体   中英

Error trying to run seeds: Knex: Timeout acquiring a connection. The pool is probably full

I'm getting this error everytime i run yarn knex seed:run :

Error while executing "/home/user/path-to-the-file/my-seed.js" seed: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

The problem is that i send the project for other people and they can run it normally, i already tried all answers about it of the internet, i don't know what to do anymore.

My database config:

const config = Object.freeze({
  client: 'pg',
  pool: {
    min: 0,
    max: 5,
    idleTimeoutMillis: 30000,
    createTimeoutMillis: 3000,
    acquireTimeoutMillis: 30000,
    reapIntervalMillis: 1000,
    createRetryIntervalMillis: 100,
    propagateCreateError: false
  },
  connection: Object.freeze({
    ...database
  })
})
  • Knex version: "^0.95.8"
  • pg version: "^8.7.1"
  • Yarn version: 1.22.11
  • Node version: 14.17.4

I already tried to downgrade pg and node, it didnt work, nothing works.

There is a issue on Knex repository saying that upgrading to latest pg solves it, but it didnt work too: https://github.com/knex/knex/issues/2820

Can someone help me?

One easy way to create this error is doing this:

const rows = [];
for (let i =  0; i < 10000; i++) {
  rows.push({ name : `foo  ${i}` });
}
await Promise.all(rows.map(data => knex('user').insert(data)));

There are infinite ways how to run out of connections, but most usual cases are opening too many concurrent transactions or running huge amount of parallel queries.

Best way to find out the reason why it happen is to remove parts of the problematic code until the error doesn't occur anymore and then investigate why that reduced test case fails.

One good way to see what knex is doing internally is to set DEBUG=knex:* environment variable, before running the code so that knex outputs information about queries, transactions and pool connections while code executes.

faced similar issued, bumped pg to 8.7.1 and it worked

also node to 16.3.1 and knex to 0.95.11

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM