knex: "TimeoutError: Knex: Timeout acquiring a connection" when using with Node 14

Environment

Node: 14.x <-- pretty sure this is the problem / difference

Knex version: 0.21.0 (also seen in older version) Database + version: Postgres 12 OS: Observed on macOS and Linux

Bug

  1. Initially, all knex connections/queries failed (timed out). I was able to fix regular connections by upgrading knex to 0.21.0 and node-pg to version 8.x. However, running migrations using knex migrate:latest or npx knex migrate:latest is still failing.

  2. Error message

TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
    at /<omitted>/node_modules/knex/lib/client.js:318:17

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 26
  • Comments: 32 (3 by maintainers)

Most upvoted comments

Update: turns out that our repository containing the migrations has a separate copy of knex/pg. Upgrading pg to 8.x in this repository seems to have fixed things for me.

I have this same error what is odd is one project on my computer it will run and work for one database… on another different project same setup just different postgresql database it does the same error. I’m on Node 14 but I’ve downgraded to 12 and there was no difference. Does anyone please have a solution for this or even to trouble shoot it?

I just resolved my problem. Upgrading your knex: "^0.21.2" and pg: "^8.3.0" seem to help. Glad someone opened this issue 😄

I had the same issue with Node.js 14.0.0 (latest), knex 0.21.1 (latest), and pg 7.8.12. Upgrading pg to 8.0.3 fixed the issue.

@Robmcmon Note that you will also get this error if the database is inaccessible for some reason (e.g. if you have a typo in the server address, your database is genuinely down, there’s a firewall blocking the connection, or you have no internet on the machine you are connecting from). Given that you are seeing this on Node 12 as well I’d suggest that it’s likely unconnected to the issue seen here.

However, you may also wish to check that you definitely have an 8.x version of node-postgres (pg) installed (you could delete node modules and reinstall to be sure), as this seemed to fix the issue for Node 14.

Hey @kibertoad - pg 8.0.3 did fix it for me - my lock file looks like this:

"@keystonejs/adapter-knex@^9.0.0", "@keystonejs/adapter-knex@^9.0.3":
  version "9.0.3"
  resolved "https://registry.yarnpkg.com/@keystonejs/adapter-knex/-/adapter-knex-9.0.3.tgz#e87b8547c3de386b81718904792275f1343f1c4b"
  integrity sha512-qDFOGPBGVC8vemqyrgDBr2WKffp2iMVUyhCu7xciSkaK9+EaJWBtoLr6kUi9si6zOJ9eiOjGr3GjfUQNBmZR8A==
  dependencies:
    "@keystonejs/fields-auto-increment" "^5.1.6"
    "@keystonejs/keystone" "^8.1.2"
    "@keystonejs/logger" "^5.1.1"
    "@keystonejs/utils" "^5.4.0"
    "@sindresorhus/slugify" "^0.11.0"
    knex "0.21.1"
    p-settle "^3.1.0"
    pg "8.0.3"

I will make a ticket with Keystone to get all the dependencies changed around 😃 thanks for your help!

I’m stuck on this issue for 3 days, i already tried all possible solutions on the internet and have no idea what is going on. I sent the project for other friends to test and it works normally, but to me this error persist, i have all package on last version, node, yarn and npm on last version, still i get this error.

The error is throw when trying to run a seed, inserting data in a table using Knex.

Already tried to downgrade node, pg, and knex, nothing works. Tried to change postgres config max_connections and shared_buffers, nothing too.

Tried to change knex pool config on database config to a lot of different parameters, nothing…

I don’t know what is wrong with this.

Interesting. I’m seeing this in CI for Node 12 of all things. Might be some other change in knex causing it. Does switching to older node fix it?