knex: TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
Environment
Knex version: 0.15.2 Database: sqlite3 OS: Ubuntu 18
I’m getting lots of errors like TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
Any ideas? All my code lives in this one file: https://github.com/umaar/wiki-globe/blob/master/index.js - that code powers this globe which I posted in a Hacker News comment and in turn led to the discovery of such error.
An example query looks like this:
await knex('edits').insert([{
field1: JSON.stringify(data),
field2: 'field2'
}]);
Does sqlite3 only allow a single connection to it because it’s file-based? I’ll try adding .transacting() calls to see if that makes a difference.
I guess it comes down to: some technical limitation with sqlite3 (maybe lack of pooling?) or some badly written code DB/queries on my part! Any insight you have would be much appreciated, thanks!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 56 (9 by maintainers)
Links to this issue
Commits related to this issue
- Fix knex tiemout issue. https://github.com/knex/knex/issues/2820#issuecomment-620628867 — committed to minisuperapp/specifications by alayor 4 years ago
- fixed migration and setup more info: https://github.com/knex/knex/issues/2820 — committed to tg44/nginx-proxy-manager by tg44 4 years ago
- https://github.com/knex/knex/issues/2820 — committed to codypaste/codypaste by szopqa 4 years ago
- fix: upgrade knex to 0.21.x See https://github.com/knex/knex/issues/2820#issuecomment-620628867 — committed to statechannels/statechannels by andrewgordstewart 4 years ago
- fix: upgrade knex to 0.21.x See https://github.com/knex/knex/issues/2820#issuecomment-620628867 — committed to statechannels/statechannels by andrewgordstewart 4 years ago
- nix/server: use nodejs-12 Due to ``` TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call? ``` See https://github.com/knex/knex/iss... — committed to otevrenamesta/cityvizor by sorki 3 years ago
I solved this problem with these versions:
@batadamnjanovic Thank you so much! I’ve been pulling my hair trying to understand what the hell happened. Upgrading to the latest
pgdid the trick.life saving comment.
I’ve had same problem with pg connection. Took me a while to figure out that with node v14.9.0, pg version ^8.0.3 is required. I’ve had pg version ^7.4.1, which caused problems
@joaotanaca Good way to avoid that error is to use implicit commit/rollback style of transactions
+1 having this issue too
It is a fact that this error can be caused by very many issues, today I found out a new one the hard way after scrolling up and down countless threads like this one to no avail.
when setting up the pool, there knex allows us to optionally register
afterCreatecallback, if this callback is added it is imperative that you make the call to thedonecallback that is passed as the last parameter to your registered callback or else no connection will be acquired leading to timeout.Knex version: 0.15.2 Database: MySQL 8 OS: MacOSX
I’m having the same connection issue when I run “knex migrate:latest”, and have scoured google with no luck. I’ve tested connections between Node and MySQL with a simple SQL script and that’s connecting fine. Initially there was an authentication issue with the connection which I was able to resolve by altering the user privileges with ‘mysql_native_password’ which has to be done in MySQL 8 to be able to support legacy connections I believe. However I was unable to get Knex the connection going.
Does Knex support MySQL 8? The examples in the documentation show MySQL 5.6 and there is no explicit mention of MySQL 8 support.
I know this can be anything, so here’s all the code I have for this project.
knexfile.js
knex.js
server.js
migration file
Here is the result of a console log of “knex” from knex.js
@batadamnjanovic Thank you so much, after 1 week nightmare… finally you saved me.
From the documentation:
So if you’re using sqlite3 you will run into issues with more than 1 connection.
@evanrosa We have been running our web application on port 8080 with CloudRun for several years and have the same problem. Could you please tell me why changing the port to 1337 would stop this problem?
This feeling when you think you’ll spend the entire day trying to fix such a damn issue, but you find the right spot and the right people that ease the pain in a flash 😃
Comigo funcionou atualizar as versoes
FWIW, I was getting the same error after upgrading from Node 10 to Node 14 with pg 7.12.1. Upgrading to pg 8.3.3 fixed it.
for me it was a silly error, I ended up not putting the
await trx.commit()before the return@ashanker2 I fixed problem by using config.host =
/cloudsql/${process.env.INSTANCE_CONNECTION_NAME};and not ip&port. GAE mounts tcp/unix socket to a container when you have configured Cloud SQL instance. There may be a problem if db is in a different region than service that uses it and you may need to use this beta_settings-flag in your .yaml like in the docs.
For me this was Google Cloud specific problem, because one can not take connection from GAE to Google SQL with public IP. I fixed problem by reading some more docs.