New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call? 1 #4395
Comments
Connection is automatically closed when on connection idle after idleTimeoutMillis see https://cloud.google.com/sql/docs/postgres/samples/cloud-sql-postgres-knex-timeout
and check pg - node versions #2820 (comment) and #3912 (comment)
see #2820 (comment) |
idleTimeoutMillis: 600000 Did we really require this. There must be default value less than this. Also we using lambda do we require this idleTimeoutMillis. |
You are creating transactions and never committing/rolling them back. That fills the pool until there is no connections left. Better way to use transactions with automatic commit/rollback is like this:
|
Sorry, at the time I write sample code I mistakenly forget to add commit/rollback but I have added them in actual code. But still getting the same error in between. |
Another error there is that you are creating a new query, which is outside of transaction for every result line:
Depending on result set size, those queries can overwhelm DB and are not ran fast enough to meet the acquireTimeout. Other possible problem is that if that code is ran concurrenctly many times it is possible that first 100 concurrent transactions take all the connections and then that log write query is not ran in transaction and there might not be any connections left in pool so transactions will never be finished. |
I didn't get the context of "Another error there is that you are creating a new query, which is outside of transaction for every result line:" |
So using this way we will never fall into this error and connection will get manage properly? |
It can still happen, but probably in that case you need more resources to the database, since error will be caused because of DB not being able to handle queries fast enough. |
That query is not executed through the same transaction that the first query is. |
But I passing all the same transaction instance created in first like outside the try catch block. |
We are using db.m6g.large. and we. using lambda function. |
Absolutely agree with you. From my code when I try to debug query in knex using DEBUG:knex:* I found out that all query executing in the same transaction but the connection is not getting release back at the end to the pool after taken. I try your method which automatically commit + release connection back to pool on return and rollback on throw error. |
I'm having the same problem, i'm using the transaction like this
"inside of this code there are some rows, but I removed it for better comprehension". I tested a lot of times, and the pool is getting full and don't commiting the transactions, if I save the project when It running the commit occurs, I really don't know what happens. I'm using: and I tried another versions of node, pg, knex and ts-node, none of them have solved my problem. Anyone have the same problem? |
adding |
Hi! guys in my application I was facing (sometime in between)
TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
My config of knex is
and I'm using it something like
The text was updated successfully, but these errors were encountered: