Node oracledb: NJS-040: connection request timeout. Request exceeded queueTimeout of 60000

8.3k views Asked by At

I have an nodejs application that using oracledb module to connect many oracle database. This application is monitoring all databases in one place.

But there is a problem. I am creating a file to connect to oracle db and execute sql's. I am using this file to connect to databases. For example:

let conections = [];
function connectToDb(dbid, connStr){
   const oracledb = require('oracledb');
   oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
   oracledb.poolMax = 10;
   oracledb.poolMin = 1;
   oracledb.createPool(connStr).then((conn) => {
      conections[dbid] = dbid;
   });
}

function executeSql(dbid, sql, callback){
    conections[dbid].getConnection().then(conn => {
        conn.execute(qry, params, function(err, rows) {
            callback(rows);
        });
    });
}

connectToDb(1, {......});
connectToDb(2, {......});
connectToDb(3, {......});

executeSql(1, 'select * from ....', function(){...}); //response time 1 sn everthing is okey
executeSql(2, 'select * from ....', function(){...}); //response a long time. Than i am getting queue timeout error
executeSql(3, 'select * from ....', function(){...}); //it not working a while time!!
executeSql(1, 'select * from ....', function(){...}); //it not working a while time!!

//this functions are async. Please assume that there is setInterval function.

in this code, everthing is okey but when an database get NJS-040: connection request timeout. Request exceeded queueTimeout of 60000 error for one database, all databases are effecting by this situation.

I think these connections not isolated and I think that if I can create isolated connections this stuation will be solve. For example can i using import instead of require?

Thank you for your helps

2

There are 2 answers

1
roll1D20 On

At some point you have to:

await connection.close();

Otherwise you're essentially opening a new connection to the database pool without closing the other connections. I ran into this problem myself re-coding an API.

0
tuananh On

There is a setting to increase connection request timeout oracledb.queueTimeout = 3000; // 3 seconds (https://github.com/oracle/node-oracledb/blob/main/doc/api.md#propdbqueuetimeout)

Or you can read more about thread here https://oracle.github.io/node-oracledb/doc/api.html#numberofthreads