Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

I am using the following code to make a knex connection, but frequently the error occurred

Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

Can anyone please suggest the solution for this issue?

var knexConn = reqKnex({         client: pClient,         native: false,         connection: pConn,         searchPath: pSearchPath,         pool: {             max: 7,             min: 3,             acquireTimeout: 60 * 1000         }     });   function getTransactionScope(pKnex, callback) {     try {         pKnex.transaction(function(trx) {             return callback(trx);         });     } catch (error) {         console.log(error);     } }  function ExecuteSQLQuery(pTranDB, pTrx, pQuery, pCallback) {     try {         var query = pTranDB.raw(pQuery);          if (pTrx) {             query = query.transacting(pTrx);         }         query.then(function(res, error) {             try {                 if (error) {                     console.log(error);                 } else {                     return pCallback(res, error);                 }             } catch (error) {                 console.log(error);             }         }).catch(function(error) {             return pCallback(null, error);         });     } catch (error) {         console.log(error);     } }  function Commit(pTrx, pIsCommit) {     try {         if (pIsCommit) {             pTrx.commit();         } else {             pTrx.rollback();         }     } catch (error) {         console.log(error);     } } 
like image 608
Shanthi Balraj Avatar asked Nov 05 '16 06:11

Shanthi Balraj


People also ask

How do I debug KNEX?

How do I debug? # Knex is beginning to make use of the debug module internally, so you can set the DEBUG environment variable to knex:* to see all debugging, or select individual namespaces DEBUG=knex:query,knex:tx to constrain a bit.

What is KNEX NPM?

Knex is a SQL query builder, mainly used for Node. js applications with built in model schema creation, table migrations, connection pooling and seeding.

What is KNEX used for?

Knex is a technique that is used to build queries. It supports various databases like Postgres, MySQL, SQLite, Oracle, and some others as well. It provides both callbacks and promise interface. It provides connection pooling and standardized responses.


2 Answers

I solved this problem with these versions:

"knex": "^0.21.1", "objection": "^2.1.3", "pg": "^8.0.3" 
like image 109
Bratislav Damnjanovic Avatar answered Sep 21 '22 10:09

Bratislav Damnjanovic


I had this issue recently, and I had just updated to Node v14.2.0

enter image description here

This version seems to have a breaking change to knex. Luckily I have NVM so I switch to another version (v12.16.3) and this solved the issue.

enter image description here

Good luck!

like image 45
wiredmartian Avatar answered Sep 20 '22 10:09

wiredmartian